WordPress 全英文垃圾评论拦截

一般来说,大部分垃圾评论内容为外文,一般都是英文,还带有很多链接等。
大部分博主都是用汉文写博,评论几乎很少有英文评论,所以我们针对性的拦截没有包含中文的评论。

我们采用代码的形式,不用插件来拦截,插件显得很繁琐,麻烦,现在我们只需把一下代码添加到博客主题Fuctions.php中就可以了。很简单,效果也是出奇的好。

<code>
<?php
// 禁止全英文评论
add_theme_support('automatic-feed-links'); // Add default posts and comments RSS feed links to head

function scp_comment_post( $incoming_comment ) {
    $pattern = '/[一-龥]/u';
    
    if(!preg_match($pattern, $incoming_comment['comment_content'])) {
        wp_die( "You should type some Chinese word (like \"你好\") in your comment to pass the spam-check, thanks for your patience! 您的评论中必须包含汉字!" );
    }
    return( $incoming_comment );
}
add_filter('preprocess_comment', 'scp_comment_post');
?></code>

这样减少了全英文垃圾评论的影响了~

[mp3]http://storage.live.com/items/DFE53C4470F7CD32!114?filename=%E6%A0%B9%E5%91%B7%20-%20%E9%98%BF%E7%88%B8%E9%98%BF%E5%A6%88.mp3[/mp3]

0 thoughts on “WordPress 全英文垃圾评论拦截
添加一条新回复 回到顶部

亲爱的,主人已经关闭了这篇文章的评论 。