Validate::validate_max_string_length( object $field )
Description #
Validate if length of a string is at least as defined.
Parameters #
- $fieldobject (Required) Instance of @see
AP_Fieldobject.
Source #
File: lib/class-validate.php
public static function validate_max_string_length( $field ) {
$value = $field->value();
if ( ! empty( $value ) && $field->get( 'max_length' ) ) {
$max_length = $field->get( 'max_length', 10 );
$value = wp_strip_all_tags( $value );
$value = html_entity_decode( $value, ENT_XML1, 'UTF-8' );
if ( mb_strlen( $value, 'utf-8' ) > $max_length ) {
$field->add_error(
'max-string-length',
sprintf(
// Translators: placeholder contain field label.
__( 'Value provided in field %1$s must not exceeds %2$d characters.', 'anspress-question-answer' ),
$field->get( 'label' ),
$max_length
)
);
}
}
}
Expand full source code Collapse full source code View on GitHub: lib/class-validate.php:466
Add your comment