Last active
March 3, 2025 13:24
-
-
Save wpchannel/8ef7b3e51550a201c73c5c8ed26d0b82 to your computer and use it in GitHub Desktop.
Block emails for a specific Gravity Forms (Eric Jones spam)
This file contains hidden or 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
function wpc_block_emails_on_form_submission( $result, $value, $form, $field ) { | |
// Ensure the field is an email type and the value is a valid string | |
if ( $field->type === 'email' && is_string( $value ) && ! empty( $value ) ) { | |
// List of blocked emails (can be modified via a filter) | |
$blocked_emails = apply_filters( 'wpc_blocked_emails', [ '[email protected]' ] ); | |
// Normalize the email (trim spaces and convert to lowercase) | |
$email = mb_strtolower( trim( $value ) ); | |
// Check if the email is in the blocked list | |
if ( in_array( $email, $blocked_emails, true ) ) { | |
$result['is_valid'] = false; | |
$result['message'] = __( 'Cette adresse e-mail est incorrecte. Veuillez en utiliser une autre.', 'wpchannel' ); | |
} | |
} | |
return $result; | |
} | |
// Hook the function into Gravity Forms field validation | |
add_filter( 'gform_field_validation', 'wpc_block_emails_on_form_submission', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added check for $value
Added a hook to filter blacklist