Home Experience & Tips Sharing Standard Post

Standard Post

WordPress Restricts Allowed Email Types for Registration (Email Blacklist/Whitelist)

More and more people are now using WordPress to build resource download sites or foreign trade websites, and many have enabled user registration. If you check the backend user list, you will find many accounts registered by bots in batches, with email addresses from uncommon domain mailboxes. We can use the following two methods to simply restrict email service providers during WordPress registration. …

Posted on August 30, 2020 About 3 minutes reading
WordPress限制可以注册的邮箱类型(邮件黑白名单)

Nowadays, more and more people are using WordPress to buildResource Download Siteor foreign trade websites, many of which have user registration enabled. If you check the Admin Dashboard user list, you'll find many accounts registered in bulk by bots, with email addresses from uncommon domain mailboxes. We can use the following two methods to simply restrict the email service providers allowed during WordPress registration.

Email Whitelist for Registration

For domestic users, it's recommended to use an email registration whitelist, because your main users are Chinese, and there are rarely registrations from users of those obscure domain mailboxes. We can allow registration only from common email services.

Usage Method: Copy the code below and paste it into the website theme's functions.php file.

/*
* WordPress注册邮箱白名单
* https://blog.naibabiji.com/skill/mail-registration-restrictions.html ‎
*/
function is_valid_email_domain($login, $email, $errors ){
$valid_email_domains = array("gmail.com","qq.com");// 允许注册的邮箱信息
$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>: 本站只支持gmail和QQ邮箱注册。' ));
}
}
add_action('register_post', 'is_valid_email_domain',10,3 );

Registration Email Blacklist

If you have a foreign trade website, you will encounter many foreign users registering. They may use domain email addresses. You can check the backend user registration records to determine which domain email addresses are spam, and directly block registration from that domain.

At this point, you can use the Ban Hammer plugin, which makes it very convenient to set up a domain blacklist.

Wordpress邮箱注册黑名单

Download Link

In addition to email whitelists and blacklists, we can also add a simple registration verification to the website registration process to prevent bots from bulk registering. For example, to register for Naibabiji, you need to answer a question first to pass.

5/5 - (1 vote)
Previous WordPress Redirect to Current Page After Login Code Continue reading content around the same timeline. Next WordPress 5.5.1 Update Log – 34 Bug Fixes and 4 Enhancements View the next related tutorial or experience.

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: