- This topic has 0 replies, 1 voice, and was last updated 5 months, 3 weeks ago by .
Viewing 0 reply threads
Viewing 0 reply threads
- You must be logged in to reply to this topic.
Welcome › mkmcst community Forum › Web programming › WordPress › Random wordpress › Allow registration for certain email domain on WordPress
function is_valid_email_domain($login, $email, $errors ){
$valid_email_domains = array("gmail.com","yahoo.com");// whitelist email domain lists
$valid = false;
foreach( $valid_email_domains as $d ){
$d_length = strlen( $d );
$current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
if( $current_email_domain == strtolower($d) ){
$valid = true;
break;
}
}
// if invalid, return error message
if( $valid === false ){
$errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: you can only register using @gmail.com or @yahoo.com emails' ));
}
}
add_action('register_post', 'is_valid_email_domain',10,3 );
Now look at the second line of the above code:
$valid_email_domains = array(“gmail.com”,”yahoo.com”);// whitelist email domain lists
You will see where to list the email domain for whitelist those email which you want users to be able to register on your WordPress site. You can list more email and those email domain which you want to be allowed for user registration on your WP site. Just place those email domain in the same manner by comma separated and inside the quotation.