Skip to content

Instantly share code, notes, and snippets.

@DumahX
Created January 13, 2022 15:49
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 DumahX/fd4fb4474af8518ff6b4ea9ad2063eef to your computer and use it in GitHub Desktop.
Save DumahX/fd4fb4474af8518ff6b4ea9ad2063eef to your computer and use it in GitHub Desktop.
<?php
function mepr_restrict_email_domains($errors) {
# Allowed email domains.
$allowed_email_domains = array('gmail.com', 'hotmail.com');
$email_address = isset($_POST['user_email']) ? trim($_POST['user_email']) : '';
# Don't bother validating if the email is empty.
if(empty($email_address)) {
return $errors;
}
$user_email_array = explode('@', $email_address);
$user_email_domain = array_pop($user_email_array);
# Check if the user's email domain is allowed.
if(!in_array($user_email_domain, $allowed_email_domains)) {
$errors[] = 'Your email domain is blocked from signing up.';
return $errors;
}
return $errors;
}
add_filter('mepr-validate-signup', 'mepr_restrict_email_domains');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment