Reject WPForms Messages in Foreign Scripts
Blocks WPForms submissions written mostly in Cyrillic, Chinese or another script your business never receives genuine messages in.
Opens WPIDE on
Code
$wpide_wpf_blocked_scripts = array( 'Cyrillic', 'Han', 'Arabic', 'Hangul', 'Thai' );
$wpide_wpf_script_share = 0.3;
add_filter( 'wpforms_process_honeypot', function ( $honeypot, $fields, $entry, $form_data ) use ( $wpide_wpf_blocked_scripts, $wpide_wpf_script_share ) {
if ( $honeypot || empty( $entry['fields'] ) ) {
return $honeypot;
}
$text = '';
foreach ( (array) $entry['fields'] as $value ) {
$text .= ' ' . ( is_array( $value ) ? implode( ' ', $value ) : (string) $value );
}
$letters = preg_match_all( '/\p{L}/u', $text );
if ( $letters < 10 ) {
return $honeypot;
}
$foreign = 0;
foreach ( $wpide_wpf_blocked_scripts as $script ) {
$foreign += (int) preg_match_all( '/\p{' . $script . '}/u', $text );
}
return $foreign / $letters >= $wpide_wpf_script_share ? 'Your message could not be sent.' : $honeypot;
}, 10, 4 );
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.