登录

wordpress禁止英文(外语)/email/url评论回复

wordpress建站 maolai 1076次浏览 0个评论

对于开启wordpress评论回复,如果没有限制设置,每天都会有很多垃圾评论,特别是一些英文、url、邮件评论等。wordpress 总是被人垃圾评论,可以通过相关插件、验证码等来防止恶意的垃圾评论攻击。将以下代码添加到你主题的模板函数 (functions.php)下可过滤外文评论、屏蔽关键词,email,url,ip等。

wordpress禁止英文(外语)/email/url评论回复

//屏蔽关键词,email,url,ip
if (git_get_option('git_spam_keywords') && !is_user_logged_in()):
function Googlofuckspam($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', 'Googlofuckspam');
//过滤外文评论
if (git_get_option('git_spam_lang') && !is_user_logged_in()):
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');

本文由maolai编辑整理发布,转载请注明wordpress禁止英文(外语)/email/url评论回复
喜欢 (0)
[maolai]
分享 (0)
maolai
关于作者:
无折腾,不生活。一个爱折腾,爱分享的90后,欢迎你认识我,我是MAOLAI。
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

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