wordpress防止全英文评论

一般的spam都是英文,最近的就不是了,而是很多中文,汗一个。我们可以在function里面添加代码,防止第一次留言是英文的评论,这样子就可以减少很多垃圾评论了。

function v7v3_en($comment) {
$pattern = '/[一-龥]/u';
$cau=$comment['comment_author'] ;
$cem=$comment['comment_author_email'] ;
global $wpdb;
$ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$cau' AND comment_author_email = '$cem' and comment_approved = '1' LIMIT 1");
if( is_user_logged_in() || 1 == $ok_to_comment ){ return $comment; }
elseif ( !preg_match_all($pattern, $ccontent, $match) ) {
exit('
<head><meta http-equiv="Content-Type" content="text/html; charset=utf8"/></head>
初次评论不允许纯英文哦~<a href="javascript:history.go(-1);">向上一页</a>');
}
}
add_filter('preprocess_comment', 'v7v3_en');
function v7v3_comment_post( $incoming_comment ) {
$http = '/[<|KTV|ッ|の|ン|優|業|グ|貿|]/u';
if(preg_match($http, $incoming_comment['comment_content'])) {
wp_die( "
<head><meta http-equiv='Content-Type' content='text/html; charset=utf8'/></head>
您的评论包含敏感关键词,被系统判断为垃圾评论!<a href='javascript:history.go(-1);'>向上一页</a>" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'v7v3_comment_post');

0 个主题帖 其中:热心观众:0 个, 管理员:0 个

抱歉,评论被关闭