禁止WordPress黑名单中的垃圾评论提交到数据库

如果你是使用WordPress有段时间的同学,你就会发现,垃圾评论真的太可恶了,各种有,虽然我们设置了不审核不会显示,可是邮件神马的发的好烦,于是转了一个教程,介绍利用WordPress自带的黑名单功能,禁止垃圾评论提交到数据库。
将下面的代码放到你主题的functions.php中:

//禁止垃圾评论提交到数据库
function uedsc_fuckspam($comment) {
if(is_user_logged_in()){ return $comment;} //登录用户不检测评论
if(wp_blacklist_check($comment["comment_author"],$comment["comment_author_email"],$comment["comment_author_url"], $comment["comment_content"], $comment["comment_author_IP"], $comment["comment_agent"] )){
header("Content-type: text/html; charset=utf-8");
wp_die("您评论包含辱骂,过激或者违反法律等言论,或者您的IP已被加入黑名单,如有疑问请联系管理员处理!返回文章页");
} else {
return $comment;
}
}
add_filter("preprocess_comment", "uedsc_fuckspam");

 
黑名单如图所示:

WordPress黑名单

可能一些新人一下在还找不到在哪设置wordpress评论黑名单关键词:登陆 -> 设置 -> 讨论,即可看到评论黑名单了。设置完评论黑名单后就能防住部分非法广告评论了,当然你也可以把一些经常发垃圾评论的ip加入到黑名单,这样就可以屏蔽该IP在你网站上评论了。
当然,这里我提供一些黑名单供大家使用。
黑名单:http://wpmeeimg.b0.upaiyun.com/2014/05/fuckspam.txt
参考文章:http://www.uedsc.com/wordpress-fuck-spam.html