在你主题的functions.php中添加以下代码
function refused_spam_comments( $comment_data ) { $pattern = '/[一-龥]/u'; if(!preg_match($pattern,$comment_data['comment_content'])) { wp_die('评论必须含中文!'); } return( $comment_data ); } add_filter('preprocess_comment','refused_spam_comments');
其中[一-龥]这个正则表达式代表所有中文,这时纯英文的垃圾评论算是过滤掉了,但是还有另外一种垃圾评论,日文的……
日文的采用同样的方法,请几个常出现的日文假名写入到正则表达式中ッ、の、ン、優、業、グ、貿
function fuckjp_comment_post( $incoming_comment ) { $http = '/[<|=|.|友|夜|KTV|ッ|の|ン|優|業|グ|貿|]/u'; if(preg_match($http, $incoming_comment['comment_content'])) { wp_die( "日本广告离开!" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'fuckjp_comment_post');
标签:WordPress
相关阅读 >>
wordpress编辑器中添加链接功能自动加入nofollow的方法
wordpress主题中添加文章列表页页码导航的php代码实例
wordpress 静态化设置 windows主机伪静态去除index.php方法
禁用wordpress gravatar使用本地头像提高网页打开速度
更多相关阅读请进入《wordpress》频道 >>