因此,我正在寻找一种方法来阻止特定电子邮件在我的网站上注册帐户。它是一个wordpress.org网站。
我尝试过Ban Hammer插件,但它无法正常工作。
我不是在寻找评论,而是在寻找合适的网站。就像我可以放在functions.php或某个地方的代码一样,当这个特定的电子邮件用于尝试在我的网站上注册帐户时,就会出错。
不是整个电子邮件域,例如@ gmail.com。但是一封特定的电子邮件,例如stack@gmail.com。
任何人都知道如何做到这一点?
编辑:我在这里找到了这个教程:http://www.davidtiong.com/block-spam-registrations-on-wordpress/
我尝试在最后一个上方的Functions.php文件中添加它?>在文件的最底部:
function dtwd_blocked_emails($user_email) {
$dtwd_blocked_list = array("slojehupri@thrma.com", );
$user_email_split = explode('@', $user_email); $user_email_domain = $user_email_split[1];
if (in_array($user_email_domain, $dtwd_blocked_list)) {
//Return 1, for detection
return 1;
} else {
//Return 0 for no detection
return 0;
}
}
我还在主题的register.php中添加了这个:
elseif ( dtwd_blocked_emails( $user_email ) == 1) {
$errors->add( 'blocked_email', __( '<strong>ERROR</strong>: This email is not allowed.' ) );
}
我在我主题的login.php中添加了相同的代码。
然后我尝试使用此电子邮件注册一个帐户(现在应该被阻止):slojehupri@thrma.com
该网站允许我注册,它允许我登录。电子邮件现在应该被阻止,并在我尝试注册和/或使用它时返回错误。
答案 0 :(得分:1)
我不确定该功能应该如何工作(它甚至没有挂钩......)。我没有对此进行测试,但听起来就像运行registration_errors
过滤器挂钩时验证电子邮件一样简单。来自食典委:
registration_errors
过滤器挂钩过滤了注册新用户时遇到的错误。如果$errors
中存在任何错误,则会中止用户的注册。
这听起来与您想要做的完全一样(如果用户电子邮件在您的黑名单中,则中止注册)。同样,这还没有经过测试,但我会在 functions.php 中尝试以下内容:
function so_32767928_blacklisted_user( $errors, $sanitized_user_login, $user_email ) {
// One or more blacklisted emails to validate against
$blacklist = array( 'slojehupri@thrma.com', );
// If the user trying to register is in the blacklist, add an error message
if ( in_array( $user_email, $blacklist ) ) {
$errors->add( 'blacklist_error', '<strong>ERROR</strong>: This email is not allowed to register on this site.' );
}
// Always return $errors, even if there are none
return $errors;
}
add_filter( 'registration_errors', 'so_32767928_blacklisted_user', 10, 3 );