Validate::validate_badwords( object $field )
Description #
Validate if there are minimum items in an array.
Parameters #
- $fieldobject (Required) Instance of @see
AP_Fieldobject.
Source #
File: lib/class-validate.php
public static function validate_badwords( $field ) {
$value = $field->unsafe_value();
$found = array();
foreach ( (array) self::get_bad_words() as $w ) {
$w = trim( $w );
$count = preg_match_all( '/\b' . preg_quote( $w, '/' ) . '\b/i', $value );
if ( $count > 0 ) {
$found[ $w ] = $count;
}
}
if ( ! empty( $found ) ) {
$field->add_error(
'bad-words',
sprintf(
// Translators: placeholder contain field label.
__( 'Found bad words in field %s. Remove them and try again.', 'anspress-question-answer' ),
$field->get( 'label' )
)
);
}
}
Expand full source code Collapse full source code View on GitHub: lib/class-validate.php:584
Add your comment