WordPress站点屏蔽过滤垃圾评论教程(Akismet反垃圾评论插件)

前段时间我的WordPress站点经常收到垃圾评论的轰炸,严重时一天会收到几十条垃圾评论。我这个小破站一没啥流量,二又不盈利,实在是不太理解为啥有人要这么执着地浪费资源在上面。

Akismet反垃圾评论插件
其实用了 Akismet 反垃圾评论插件后,那些垃圾评论已经会被过滤到 WP 后台的垃圾评论列表。Akismet 这个插件在我网站的准确率还是挺高的,基本上能识别出99%以上的垃圾评论。

1.进入 WordPress 后台 > 设置 > 讨论,设置审核评论条件。

2.在禁止使用的评论关键词一栏中,根据你收到的垃圾评论特征归纳出关键词填入即可。
在这里插入图片描述
通常情况下,这样设置之后垃圾评论就会少很多~ 如果这个方法还不奏效,那可以考虑关闭评论区

WordPress屏蔽国外垃圾留言评论,将文件里的代码放到当前主题的 functions.php 中; 的前面就可以了。代码参考:https://boke112.com/bkwd/4209.html 和https://loomob.com/57.html 将以下代码放到当前主题的 functions.php 文件最后一个 ?> 的前面: //防国外灌水 function scp_comment_post( $incoming_comment ) { // 禁止全英文评论 $pattern = '/[x7f-xff]/'; if(!preg_match($pattern, $incoming_comment['comment_content'])) { wp_die( "您的评论中必须包含汉字! <br /> You should type some Chinese word (like "你好") in your comment to pass the spam-check, thanks for your patience! " ); } //禁止 A 链接 if(strstr($incoming_comment['comment_content'], "<a")){ wp_die( "您的评论中不能有 A 链接,请直接填写 URL 地址" ); } // 判断 中文字符占比 $len_all = strlen($incoming_comment['comment_content']); $len_st = mb_strlen($incoming_comment['comment_content'], 'UTF-8'); if(($len_all-$len_st)/(2*$len_st) < 0.5){ wp_die( "中文字符少于百分之五十" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'scp_comment_post'); //屏蔽关键词,email,url,ip function Shield_fuckspam($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"); err(__('不好意思,您的评论违反画里网站评论规则')); } else { return $comment; } } add_filter('preprocess_comment', 'Shield_fuckspam'); //过滤外文评论 function refused_spam_comments($comment_data) { $pattern = '/[一-龥]/u'; $jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u'; if (!preg_match($pattern, $comment_data['comment_content'])) { err(__('来一波汉字吧,博主只认识汉字!You should type some Chinese word!')); } if (preg_match($jpattern, $comment_data['comment_content'])) { err(__('原谅博主吧,只听得懂岛国神片的一两句雅蠛蝶 Japanese Get out!日本语出て行け! You should type some Chinese word!')); } return ($comment_data); } add_filter('preprocess_comment', 'refused_spam_comments'); //屏蔽带连接的 function Shield_link($comment_data) { $links = '/http:\/\/|https:\/\/|www\./u'; if (preg_match($links, $comment_data['comment_author']) || preg_match($links, $comment_data['comment_content'])) { err(__('别啊,昵称和评论里面添加链接会怀孕的哟!!')); } return ($comment_data); } add_filter('preprocess_comment', 'Shield_link');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值