九月
20
有一段时间没登录本站后台管理,垃圾评论满天飞,虽然大部分已经被列为待审核状态,但是待审核评论数量都有几百条了,删待审核的垃圾评论都删到累!
于是我想,干脆不要让这些评论提交到网站数据库,直接在评论提交过程就ban掉即可。你丫的用机器发垃圾评论,我也让网站程序帮我看门好了,可疑的垃圾评论根本进不了门,省了我审核的功夫!你发得轻松,我也阻挡得轻松。
实现方法: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');
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');
(搜索结果来自:http://wordpress.org.cn/thread-173289-1-1.html)
发表评论