Skip to content

Instantly share code, notes, and snippets.

@renventura
Created April 22, 2021 12:59
Show Gist options
  • Save renventura/fc716c3fc12871ed3a1f82a45eaa8801 to your computer and use it in GitHub Desktop.
Save renventura/fc716c3fc12871ed3a1f82a45eaa8801 to your computer and use it in GitHub Desktop.
Prevent Gravity Forms entries and notifications that contain spammy words (e.g. spam)
<?php
add_action( 'gform_pre_send_email', 'keywords_check' );
/**
* Check the message field of the entry for bad words.
* If any are detected, silently discard the email and entry.
*
* @param array $email Email data
* @param string $format Email format (text or HTML)
* @param array $notification Notificaiton data
* @param array $entry Entry data
*
* @return array
*/
function keywords_check( $email, $format, $notification, $entry ) {
$stop_words = array(
'outsource',
'Madam',
' SEO ',
'long term relationship',
'free shipping',
'lead conversion'
);
foreach ( $stop_words as $stop_word ) {
if ( false !== stripos( rgar( $entry, '3' ), $stop_word ) ) {
$email['abort_email'] = true;
GFAPI::delete_entry( $entry['id'] );
return $email;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment