WordPress评论禁止针对指定内容全英文的方法

这篇文章给大家讲解一下WordPress评论禁止针对指定内容全英文的方法。具体分析如下:

WordPress评论中第一要过滤的是全英文的垃圾内容了,这个简单我们只要检查包括汉字就可以了,还有时我们希望有些敏感字不让提交,只要一个简单的过滤函数即可.

有很多朋友可能会发现有大量的英文垃圾论内容,下面给个函数,代码如下:

<?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 );
}
?>

以下代码禁止许评论中包含 <a 随便 href="/ 或者rel="nofollow"或者http://,你也可以根据自己的需要修改,代码如下:

function lianyue_comment_post( $incoming_comment ) {
$http = '/[href="|rel="nofollow"|http://|</a>]/u';
if(preg_match($http, $incoming_comment['comment_content'])) {
wp_die( "万恶的发贴机!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'lianyue_comment_post');

希望本文所述对大家的WordPress建站有所帮助。

chuangye

chuangye

chuangye

 

chuangye

Joomla的老巢