Created
October 12, 2015 10:37
-
-
Save strangerstudios/42399a77617bcddf2c3c to your computer and use it in GitHub Desktop.
Restrict Membership Signup by Email Domain (Useful for Education, Corporate, or Association Memberships)
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(!check_validity($email)) | |
{ | |
global $pmpro_msg, $pmpro_msgt; | |
$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); | |
//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; | |
} | |
function check_validity($email) | |
{ | |
$domain = getDomainFromEmail($email); | |
$valid_domains = array("yahoo.com", "*.gmail.com", "*.domain.uk"); | |
foreach($valid_domains as $valid_domain) | |
{ | |
$components = explode(".", $valid_domain); | |
$domain_to_check = explode(".", $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($valid_domain, $domain) === false)) | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have used this but showing critical error in line number 37. would you pls check this...
thanks in advance