Use the Comment Blocklist for Fluent Forms
Blocks Fluent Forms submissions that contain any word, IP address or email from WordPress's Disallowed Comment Keys list, so one blocklist protects comments and forms.
Opens WPIDE on
Code
add_filter( 'fluentform/validation_errors', function ( $errors, $data ) {
$keys = trim( (string) get_option( 'disallowed_keys' ) );
if ( '' === $keys ) {
return $errors;
}
$text = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
foreach ( (array) $data as $name => $value ) {
if ( 0 !== strpos( (string) $name, '_' ) ) {
$text .= ' ' . ( is_array( $value ) ? implode( ' ', array_filter( $value, 'is_scalar' ) ) : (string) $value );
}
}
foreach ( preg_split( '/\R/', $keys ) as $word ) {
$word = trim( $word );
if ( '' !== $word && false !== stripos( $text, $word ) ) {
$errors['_wpide_blocklist'] = array( 'Your submission could not be accepted.' );
break;
}
}
return $errors;
}, 10, 2 );
Notes
Manage the list under Settings > Discussion > Disallowed Comment Keys, one entry per line.
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.