Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created August 2, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/c3236ca17bfe3df5b3e5340183eb56c6 to your computer and use it in GitHub Desktop.
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.
<?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