/**
*WordPress 代码阻止绝大多数垃圾评论
*感谢 Willin 的 Spam 小墙
*https://www.weixiaoduo.com/anti-spam/
*/
classBing_anti_spam{
//初始化
function__construct(){
add_action('template_redirect',array($this,'tb'),1);
add_action('init',array($this,'gate'),1);
add_filter('preprocess_comment',array($this,'sink'),1);
}
//修改评论表单
functiontb(){
if(is_singular())ob_start(create_function('$input','return preg_replace("#textarea(.*?)name=(["'])comment(["'])(.+)/textarea>#","textarea$1name=$2w$3$4/textarea><textarea name="comment" cols="100%" rows="4" style="display:none"></textarea>",$input);' ) );
}
//过滤数据
function gate(){
if( !empty( $_POST['w'] ) && empty( $_POST['comment'] ) ) $_POST['comment'] = $_POST['w'];
else{
$request = $_SERVER['REQUEST_URI'];
$referer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : __( '隐瞒', 'Bing' );
$IP = isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ? $_SERVER['HTTP_X_FORWARDED_FOR'] . __( '(通过代理)', 'Bing' ) : $_SERVER['REMOTE_ADD'];
$way = isset( $_POST['w'] ) ? __( '手动操作', 'Bing' ) : __( '未经过评论表单', 'Bing' );
$spamcom = isset( $_POST['comment'] ) ? $_POST['comment'] : null;
$_POST['spam_confirmed'] = sprintf( __( "请求:%sn 来路:%snIP:%sn 方式:%sn 内容:%sn 记录成功", 'Bing' ), $request, $referer, $IP, $way, $spamcom );
}
}
//检测评论
function sink( $comment ){
if ( !empty( $_POST['spam_confirmed'] ) ){
if( in_array( $comment['comment_type'], array('pingback', 'trackback') ) ) return $comment;
die;
}
return $comment;
}
}
if( !current_user_can( 'level_0'))$anti_spam=newBing_anti_spam;