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

2015年3月14日15:16:48 发表评论

阿里云服务器

对于开启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

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: