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');
- 粉丝: 0
- 资源: 2
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助