最近不知道什么情况,发现新wordpress网站多出了几个全英文评论,但本人不想再增加插件来解决这个问题了,所以在网上搜索了下方法。
在您主题的function.php
文件里增加一个钩子就可以安全解决了,代码如下:
<?php
function scp_comment_post( $incoming_comment ) {
$pattern = '/[x7f-xff]/';
// 禁止全英文评论
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');
?>