Created
July 15, 2024 16:25
-
-
Save Garconis/863bd39fa49419a88ea9215e5e3245b8 to your computer and use it in GitHub Desktop.
Gravity Forms | Create email address blacklist to send to spam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'gform_entry_is_spam_6', 'filter_gform_email_is_blacklist', 11, 3 ); | |
function filter_gform_email_is_blacklist( $is_spam, $form, $entry ) { | |
if ( $is_spam ) { | |
return $is_spam; | |
} | |
$field_id = '2'; // The ID of the field containing the email address to be checked. | |
$email = rgar( $entry, $field_id ); | |
// List of email addresses that when found in the email input value, will mark the entry as spam. | |
$emails_to_block = array( | |
'jon@example.com', | |
'anotheruser@example.io', | |
'info@acmeproducts.com', | |
); | |
if ( GFCommon::is_invalid_or_empty_email( $email ) ) { | |
if ( method_exists( 'GFCommon', 'set_spam_filter' ) ) { | |
GFCommon::set_spam_filter( rgar( $form, 'id' ), 'FS blacklist', 'The email was empty or invalid.' ); | |
} | |
return true; | |
} | |
// if the email address wasn't empty and it included one of the blocked emails | |
if ( ! empty( $email ) && in_array( $email, $emails_to_block ) ) { | |
// log the note | |
if ( method_exists( 'GFCommon', 'set_spam_filter' ) ) { | |
GFCommon::set_spam_filter( rgar( $form, 'id' ), 'FS blacklist', 'The email was in our blocklist.' ); | |
} | |
// mark it as spam | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment