用了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');
这样就可以实现禁止评论纯英文日文的垃圾评论了,本站测试截图:
未经授权不得转载,转载时请注明出处。
评论(0)