Reject Fluent Forms Messages in Foreign Scripts
Stops Fluent Forms submissions that are written mostly in Cyrillic, Chinese or another script your business does not receive genuine messages in.
Opens WPIDE on
Code
$wpide_ff_blocked_scripts = array( 'Cyrillic', 'Han', 'Arabic', 'Hangul', 'Thai' );
$wpide_ff_script_share = 0.3;
add_filter( 'fluentform/validation_errors', function ( $errors, $data ) use ( $wpide_ff_blocked_scripts, $wpide_ff_script_share ) {
$text = '';
foreach ( (array) $data as $name => $value ) {
if ( is_string( $value ) && 0 !== strpos( (string) $name, '_' ) ) {
$text .= ' ' . $value;
}
}
$letters = preg_match_all( '/\p{L}/u', $text );
if ( $letters < 10 ) {
return $errors;
}
$foreign = 0;
foreach ( $wpide_ff_blocked_scripts as $script ) {
$foreign += (int) preg_match_all( '/\p{' . $script . '}/u', $text );
}
if ( $foreign / $letters >= $wpide_ff_script_share ) {
$errors['message'] = array( 'Your message could not be sent.' );
}
return $errors;
}, 10, 2 );
Notes
Remove scripts from the list that your customers actually write in.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.