WP Anti Spam 小墙 1.84 代码

最近又在折腾了,发现Akismet不付费,不绑定银行卡已经是不能用的状态了,虽然一早就有耳闻,但是一直没有把这当回事儿,直到今天与spam 来了一次偶遇,让我尴尬的不要不要的,于是想起了让人无比幸福的小墙。
  • 插件作者:@willin
  • 原文链接:WP Anti Spam 小牆 1.84(已经不打开了)
  • 简单说明:可以替代Akismet来拦截垃圾评论。
  • 使用方法:将代码复制到functions.php保存。
/* <<小牆>> Anti-Spam v1.84 by Willin Kan. */
class anti_spam {
  function anti_spam() {
    if ( !current_user_can('read') ) {
      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=$2w$3$4/textarea><textarea name=\"comment\" cols=\"100%\" rows=\"4\" style=\"display:none\"></textarea>",$input);') );
    }
  }
  // 檢查
  function gate() {
    $w = 'w';
    if ( !empty($_POST[$w]) && empty($_POST['comment']) ) {
      $_POST['comment'] = $_POST[$w];
    } else {
      $request = $_SERVER['REQUEST_URI'];
      $way     = isset($_POST[$w]) ? '手動操作' : '未經評論表格';
      $spamcom = isset($_POST['comment']) ? $_POST['comment'] : '';
      $_POST['spam_confirmed'] = "請求: ". $request. "\n方式: ". $way. "\n內容: ". $spamcom. "\n -- 記錄成功 --";
    }
  }
  // 處理
  function sink( $comment ) {
    // 不管 Trackbacks/Pingbacks
    if ( in_array( $comment['comment_type'], array('pingback', 'trackback') ) ) return $comment;
 
    // 已確定為 spam
    if ( !empty($_POST['spam_confirmed']) ) {
      // 方法一: 直接擋掉, 將 die(); 前面兩斜線刪除即可.
      die();
      // 方法二: 標記為 spam, 留在資料庫檢查是否誤判.
      // add_filter('pre_comment_approved', create_function('', 'return "spam";'));
      // $comment['comment_content'] = "[ 小牆判斷這是Spam! ]\n". $_POST['spam_confirmed'];
      // $this->add_black( $comment );
    } else {
      // 檢查頭像
      $f = md5( strtolower($comment['comment_author_email']) );
      $g = sprintf( "http://%d.gravatar.com", (hexdec($f{0}) % 2) ) .'/avatar/'. $f .'?d=404';
      $headers = @get_headers( $g );
      if ( !preg_match("|200|", $headers[0]) ) {
        // 沒頭像的列入待審
        add_filter('pre_comment_approved', create_function('', 'return "0";'));
        //$this->add_black( $comment );
        }
    }
    return $comment;
  }
  // 列入黑名單
  // function add_black( $comment ) {
    // if (!($comment_author_url = $comment['comment_author_url'])) return;
    // if (strpos($comment_author_url, '//')) $comment_author_url = substr($comment_author_url, strpos($comment_author_url, '//') + 2);
    // if (strpos($comment_author_url, '/'))  $comment_author_url = substr($comment_author_url, 0, strpos($comment_author_url, '/'));
    // update_option('blacklist_keys', $comment_author_url . "\n" . get_option('blacklist_keys'));
  // }
}
$anti_spam = new anti_spam();
// -- END ----------------------------------------


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值