Files
medicalalert-web-reloaded/wp/wp-content/plugins/contact-form-7/includes/swv/rules/maxlength.php
Tony Volpe 4eb982d7a8 Merged in feature/from-pantheon (pull request #16)
code from pantheon

* code from pantheon
2024-01-10 17:03:02 +00:00

47 lines
869 B
PHP

<?php
class WPCF7_SWV_MaxLengthRule extends WPCF7_SWV_Rule {
const rule_name = 'maxlength';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
if ( empty( $context['text'] ) ) {
return false;
}
return true;
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
if ( empty( $input ) ) {
return true;
}
$total = 0;
foreach ( $input as $i ) {
$total += wpcf7_count_code_units( $i );
}
$threshold = (int) $this->get_property( 'threshold' );
if ( $total <= $threshold ) {
return true;
} else {
return new WP_Error( 'wpcf7_invalid_maxlength',
$this->get_property( 'error' )
);
}
}
}