Use the Comment Blocklist for Gravity Forms
Sends Gravity Forms entries to spam when they contain any word, IP address or email from WordPress's Disallowed Comment Keys list, so one blocklist covers comments and forms.
Opens WPIDE on
Code
add_filter( 'gform_entry_is_spam', function ( $is_spam, $form, $entry ) {
if ( $is_spam ) {
return $is_spam;
}
$keys = trim( (string) get_option( 'disallowed_keys' ) );
if ( '' === $keys ) {
return false;
}
$text = (string) rgar( $entry, 'ip' ) . ' ' . (string) rgar( $entry, 'user_agent' );
foreach ( $form['fields'] as $field ) {
$text .= ' ' . (string) $field->get_value_export( $entry );
}
foreach ( preg_split( '/\R/', $keys ) as $word ) {
$word = trim( $word );
if ( '' !== $word && false !== stripos( $text, $word ) ) {
return true;
}
}
return false;
}, 10, 3 );
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.