根据观察,Wordpress的垃圾评论中有95%是全英文评论和含有日文字符的评论,如果能够禁止这些评论的提交,也就基本上达到了Wordpress防止垃圾评论的目的了。今天就为大家分享WordPress阻止全英文和含有日文字符评论方法。

将以下代码放入function.php中,就可以阻止全英文的评论了。

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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

3、将以下代码放入function.php中,就可以阻止包含任意日文字符的评论了。

// 禁止日文评论

function BYMT_comment_jp_post( $incoming_comment ) {

$jpattern =\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’/[ぁ-ん]+|[ァ-ヴ]+/u\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

if(preg_match($jpattern, $incoming_comment[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’comment_content\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’])){

wp_die( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”禁止有日文字符的评论 You should type some Chinese word\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” );

}

return( $incoming_comment );

}

add_filter(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’preprocess_comment\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’BYMT_comment_jp_post\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部