rebase from live enviornment
This commit is contained in:
46
wp/plugins/contact-form-7/includes/swv/rules/maxlength.php
Normal file
46
wp/plugins/contact-form-7/includes/swv/rules/maxlength.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user