WordPress 添加注册邮箱白名单

wordpress/wp-content/themes/[Your-WP-Themes 你的主题]/function.php 中添加以下内容

#WordPress 注册邮箱白名单

function is_valid_email_domain($login, $email, $errors ){
	$valid_email_domains = array("gmail.com","qq.com","163.com","outlook.com","foxmail.com","vip.qq.com","aliyun.com","126.com","139.com","sina.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',__( '错误: 您无法使用该域名的邮箱来注册本站用户账号。' ));
	}
	}
	add_action('register_post', 'is_valid_email_domain',10,3 );
//----------- end -----------
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注