Skip to content

Instantly share code, notes, and snippets.

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 eighty20results/c4fb5ce37a5726da2be0 to your computer and use it in GitHub Desktop.
Save eighty20results/c4fb5ce37a5726da2be0 to your computer and use it in GitHub Desktop.
Check for FQDNs that are supposed to trigger an "invalid email domain" error on checkout
<?php
function restrict_email($value)
{
$email = $_REQUEST['bemail'];
if(is_invalid($email))
{
global $pmpro_msg, $pmpro_msgt;
//TODO: Set the error text to be whatever you want it to be:
$pmpro_msg = "Please enter a valid email address";
$pmpro_msgt = "pmpro_error";
$value = false;
}
return $value;
}
add_filter('pmpro_registration_checks','restrict_email', 10, 1);
function is_invalid($email)
{
$test_domain = getDomainFromEmail($email);
$invalid_domains = array("yahoo.com", "*.gmail.com", "*.domain.uk");
foreach($invalid_domains as $inv_domain)
{
$components = explode(".", $inv_domain);
$domain_to_check = explode(".", $test_domain);
if($components[0] == "*" && sizeof($domain_to_check > 2))
{
if($components[1] == $domain_to_check[1] && $components[2] == $domain_to_check[2])
{
return true;
}
}
else
{
if((strpos($inv_domain, $test_domain) !== false))
return true;
}
}
// The domain specified in the email address is not one of the invalid ones.
return false;
}
//Taken from: http://www.bitrepository.com/how-to-extract-domain-name-from-an-e-mail-address-string.html
function getDomainFromEmail($email)
{
// Get the data after the @ sign
$domain = substr(strrchr($email, "@"), 1);
return $domain;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment