Created
March 17, 2023 03:05
-
-
Save LittleMikeNZ/c0747d16a36375717b31fa1d01f636ed to your computer and use it in GitHub Desktop.
Wordpress/Contact Form 7: Block form submissions from @gmail.com addresses
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 cf7_check_email_field($result, $tags) { | |
$wpcf = WPCF7_ContactForm::get_current(); | |
// Check if the current form ID is 9052 | |
if ($wpcf->id !== 9052) { | |
return $result; | |
} | |
// Get the posted email data | |
$submission = WPCF7_Submission::get_instance(); | |
$posted_data = $submission->get_posted_data(); | |
$email = $posted_data['your-email']; | |
// Check if the email address is from Gmail | |
if (preg_match('/@gmail\.com$/', $email)) { | |
$result->invalidate($tags, __('We do not accept @gmail addresses.', 'text_domain')); | |
return $result; | |
} | |
return $result; | |
} | |
// Hook the function to the wpcf7_validate_email and wpcf7_validate_email* filters | |
add_filter('wpcf7_validate_email', 'cf7_check_email_field', 20, 2); | |
add_filter('wpcf7_validate_email*', 'cf7_check_email_field', 20, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment