Created
August 2, 2017 17:03
-
-
Save joshfeck/c3236ca17bfe3df5b3e5340183eb56c6 to your computer and use it in GitHub Desktop.
Validate and limit the user e-mail input to a specific domain name. WordPress.
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 | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
add_filter('is_email', 'my_custom_email_validation', 10, 3); | |
function my_custom_email_validation($email, $submittedEmail, $context) { | |
$allowed = array('example.com', 'otherexample.com'); | |
// Make sure the address is valid | |
if (filter_var($submittedEmail, FILTER_VALIDATE_EMAIL)) | |
{ | |
$explodedEmail = explode('@', $submittedEmail); | |
$domain = array_pop($explodedEmail); | |
if ( ! in_array($domain, $allowed)) | |
{ | |
return false; | |
} | |
} | |
return $email; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment