Created
February 29, 2016 12:57
-
-
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
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 | |
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