Skip to content

Instantly share code, notes, and snippets.

@wpchannel
Last active March 3, 2025 13:24
Show Gist options
  • Save wpchannel/8ef7b3e51550a201c73c5c8ed26d0b82 to your computer and use it in GitHub Desktop.
Save wpchannel/8ef7b3e51550a201c73c5c8ed26d0b82 to your computer and use it in GitHub Desktop.
Block emails for a specific Gravity Forms (Eric Jones spam)
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 );
@wpchannel
Copy link
Author

Added check for $value
Added a hook to filter blacklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment