/**
*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;