WordPress评论禁止纯英文日文

用了WordPress做博客,各位站长肯定会遇到恶意评论,可能是有些插件带的,或者一些发帖机干的,这里给大家提出解决方法,

将下面的代码添加到你的WordPress主题中的function.php文件中即可,

//评论禁止纯英文、日语
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');

这样就可以实现禁止评论纯英文日文的垃圾评论了,本站测试截图:
纯英文评论截图

未经允许不得转载:晗雅|星空 » WordPress评论禁止纯英文日文
分享到:

请选择你看完该文章的感受:

1瞧一瞧 0扯淡 0学到了 0不懂 0正能量 0无聊

评论抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址 (选填)