I am creating a website that would need to only allow some specific email addresses to signup (for example "[email protected]"). Do you guys know of any wordpress email confirmation plugins that would allow me to do that?
To clear some confusion: What I am looking for is only allowing some email addresses (for example all emails ending in @unimail.co.uk), I don't want to have to write down all of them independently. I don't really know how to code php so it would be super helpful if someone could help. Once again, sorry for the confusion created with the first question.
Thank you
I am creating a website that would need to only allow some specific email addresses to signup (for example "[email protected]"). Do you guys know of any wordpress email confirmation plugins that would allow me to do that?
To clear some confusion: What I am looking for is only allowing some email addresses (for example all emails ending in @unimail.co.uk), I don't want to have to write down all of them independently. I don't really know how to code php so it would be super helpful if someone could help. Once again, sorry for the confusion created with the first question.
Thank you
Just copy the above code and paste it into your theme’s functions.php file. Here I am going to show you the code which will reject registration from all others email addresses and Only allowing some email addresses to create an account. See the code below
function is_valid_emails($login, $email, $errors ){
$valid_emails = array("[email protected]");
$valid = false;
foreach( $valid_emails as $valid_email ){
$valid_emails_list = strtolower($valid_email);
$current_email = strtolower($email);
if( $current_email == $valid_emails_list ){
$valid = true;
break;
}
}
if( $valid === false ){
$errors->add('domain_whitelist_error',__( "<strong>ERROR</strong>: you can't register email because only allow some specific email addresses" ));
}
}
add_action('register_post', 'is_valid_emails',10,3 );
You can add more email addresses by adding more inside the code:
$valid_emails = array("[email protected]","[email protected]");
Instead of using the register_post action, you should use the registration_errors filter like this (copied from codex, then modified):
function my_awesome_email_validation_filter( $errors, $sanitized_user_login, $user_email ) {
$allowed_email_addresses = array('[email protected]','[email protected]'); //be sure to write all the allowed addresses in lowercase
if(!in_array(mb_strotolower($user_email),$allowed_email_addresses)){
$errors->add( 'email_not_allowed', __( '<strong>ERROR</strong>: Sorry, but you are not allowed to register.', 'my_textdomain' ) );
}
return $errors;
}
add_filter( 'registration_errors', 'my_awesome_email_validation_filter', 10, 3 );
Happy Coding!
https://wordpress/plugins/wp-approve-user/ Is a plugin that allows you to approve user registrations before they are allowed to login to your site. All user registrations essentially go into a Pending state until the admin user approves them.
The plugin woocommerce memberships does this. But it is pricey for just that feature. Better to use the code suggested above.