Created
March 31, 2017 17:51
-
-
Save eighty20results/21699f9db26bc843370b5a79150dd117 to your computer and use it in GitHub Desktop.
Disallow certain email domains from creating membership(s)
This file contains hidden or 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 | |
/* | |
Plugin Name: PMPro e-mail domain check | |
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/ | |
Description: Check if a domain is on the "do not allow" list for registration | |
Version: .1 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
*/ | |
function restrict_email($value) | |
{ | |
$email = $_REQUEST['bemail']; | |
if(true === 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", "*.co.uk"); | |
foreach($invalid_domains as $inv_domain) | |
{ | |
$components = explode(".", $inv_domain); | |
if($components[0] == "*") | |
{ | |
unset($components[0]); | |
$inv_domain = implode('.', $components); | |
} | |
if((stripos($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