Mark Gravity Forms Entries With Spam Words as Spam
Sends Gravity Forms entries to the Spam list when any field contains a word or phrase from your block list, so they skip notifications and stay out of your entries.
Opens WPIDE on
Code
$wpide_gf_spam_words = array( 'seo services', 'backlinks', 'crypto', 'casino', 'guest post', 'web design offer', 'loan' );
add_filter( 'gform_entry_is_spam', function ( $is_spam, $form, $entry ) use ( $wpide_gf_spam_words ) {
if ( $is_spam ) {
return $is_spam;
}
$text = '';
foreach ( $form['fields'] as $field ) {
$text .= ' ' . (string) $field->get_value_export( $entry );
}
foreach ( $wpide_gf_spam_words as $word ) {
if ( preg_match( '/\b' . preg_quote( $word, '/' ) . '\b/iu', $text ) ) {
if ( method_exists( 'GFCommon', 'set_spam_filter' ) ) {
GFCommon::set_spam_filter( rgar( $form, 'id' ), 'WPIDE blocked words', sprintf( 'Contains "%s".', $word ) );
}
return true;
}
}
return false;
}, 10, 3 );
Notes
Spam entries can still be reviewed and restored from the form's Spam list; matching is case-insensitive on whole words.
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.