spam小墙
分享一个//spam小墙
- //spam小墙
- class anti_spam {
- //建立
- function anti_spam() {
- if ( !current_user_can('level_0') ) {
- add_action('template_redirect', array($this, 'w_tb'), 1);
- add_action('init', array($this, 'gate'), 1);
- add_action('preprocess_comment', array($this, 'sink'), 1);
- }
- }
- //設欄位
- function w_tb() {
- if ( is_singular() ) {
- ob_start(create_function('$input','return preg_replace("#textarea(.*?)name=([\"\'])comment([\"\'])(.+)/textarea>#",
- "textarea$1name=$2wall$3$4/textarea><textarea name=\"comment\" cols=\"50\" rows=\"4\" style=\"display:none\"></textarea>",$input);') );
- }
- }
- //檢查
- function gate() {
- ( !emptyempty($_POST['wall']) && emptyempty($_POST['comment']) ) ? $_POST['comment'] = $_POST['wall'] : $_POST['spam_confirmed'] = 1;
- }
- //處理
- function sink( $comment ) {
- if ( !emptyempty($_POST['spam_confirmed']) ) {
- //方法一:直接擋掉, 將 die(); 前面兩斜線刪除即可.
- //die();
- //方法二:標記為spam, 留在資料庫檢查是否誤判.
- //add_filter('pre_comment_approved', create_function('', 'return "spam";'));
- /*
- $is_ping = in_array( $comment['comment_type'], array('pingback', 'trackback') );
- $comment['comment_content'] = ( $is_ping ) ?
- "◎ 這是 Pingback/Trackback, 小牆懷疑這可能是 Spam!\n" . $comment['comment_content'] :
- "[ 小牆判斷這是Spam! ]\n" . $comment['comment_content'];
- */
- // MG12 的處理方法
- $is_ping = in_array( $comment['comment_type'], array('pingback', 'trackback') );
- if(!$is_ping) {
- die();
- }
- }
- return $comment;
- }
- }
- new anti_spam();