Nowadays, more and more people are using WordPress to build
Resource 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 registrations. They may use domain-specific email addresses. We can check the backend user registration records to determine which domain emails are spam and directly block registrations from those domains. In this case, you can use the Ban Hammer plugin, which can conveniently help us set up a domain blacklist.
Download LinkIn 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.
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.