WordPress自动拒绝垃圾评论

WordPress133K阅读模式

经常受到垃圾评论的滋扰,下面的代码可能对你有所帮助。

将以下代码粘贴到你的主题functions.php模板中。

任何包含在$ bad_comment_content数组内的字符,将会被自动拒绝留言。

  1. function in_comment_post_like($string, $array) {
  2.     foreach($array as $ref) { if(strstr($string, $ref)) { return true; } }
  3.     return false;
  4. }
  5. function drop_bad_comments() {
  6.     if (!empty($_POST['comment'])) {
  7.         $post_comment_content = $_POST['comment'];
  8.         $lower_case_comment = strtolower($_POST['comment']);
  9.         $bad_comment_content = array(
  10.             'viagra',
  11.             'hydrocodone',
  12.             'hair loss',
  13.             'xanax',
  14.             'tramadol',
  15.             'russian girls',
  16.             'russian brides',
  17.             'lorazepam',
  18.             'adderall',
  19.             'dexadrine',
  20.             'no prescription',
  21.             'oxycontin',
  22.             'without a prescription',
  23.             'sex pics',
  24.             'family incest',
  25.             'online casinos',
  26.             'online dating',
  27.             'cialis',
  28.             'best forex',
  29.             'amoxicillin'
  30.         );
  31.         if (in_comment_post_like($lower_case_comment, $bad_comment_content)) {
  32.             $comment_box_text = wordwrap(trim($post_comment_content), 80"\n  "true);
  33.             $txtdrop = fopen('/var/log/httpd/wp_post-logger/nullamatix.com-text-area_dropped.txt', 'a');
  34.             fwrite($txtdrop, "  --------------\n  [COMMENT] = " . $post_comment_content . "\n  --------------\n");
  35.             fwrite($txtdrop, "  [SOURCE_IP] = " . $_SERVER['REMOTE_ADDR'] . " @ " . date("F j, Y, g:i a") . "\n");
  36.             fwrite($txtdrop, "  [USERAGENT] = " . $_SERVER['HTTP_USER_AGENT'] . "\n");
  37.             fwrite($txtdrop, "  [REFERER  ] = " . $_SERVER['HTTP_REFERER'] . "\n");
  38.             fwrite($txtdrop, "  [FILE_NAME] = " . $_SERVER['SCRIPT_NAME'] . " - [REQ_URI] = " . $_SERVER['REQUEST_URI'] . "\n");
  39.             fwrite($txtdrop, '--------------**********------------------'."\n");
  40.             header("HTTP/1.1 406 Not Acceptable");
  41.             header("Status: 406 Not Acceptable");
  42.             header("Connection: Close");
  43.             wp_die( __('bang bang.') );
  44.         }
  45.     }
  46. }
  47. add_action('init', 'drop_bad_comments');

原文:http://www.wprecipes.com/automatically-refuse-spam-comments-on-your-wordpress-blog

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
知更鸟
评论  13  访客  13
    • 光辉
      光辉 1

      这个功能还是挺实用的。赞。

      • office-worker
        office-worker 1

        这个( ^_^ )不错嘛

        • 看TV网
          看TV网 3

          这是用什么原理实现的啊?插件的代码化方式吗?只是代码并不能识别垃圾留言吧?

            • 伤逝的安详
              伤逝的安详 3

              @ 看TV网 一看你就没仔细看鸟哥正文里明明有说明,让在$ bad_comment_content里加关键词

            • 狼人
              狼人 1

              谢谢鸟哥!!!

              • Tokin
                Tokin 2

                wp后台不是有屏蔽关键词功能么。。。

                  • c
                    c 0

                    @ Tokin 我去哪都能看见你…… :shock:

                  • 减肥最快秘籍
                    减肥最快秘籍 1

                    学习了

                    • 笨鸟
                      笨鸟 4

                      这个使用了也会在错误提示时出现布局错误。

                      • 阿帮
                        阿帮 1

                        果然是名博,都是专业的文章,能学到很多东西。

                        • love02xp
                          love02xp 0

                          感谢了,已经用上啦。。。

                          • 瘦腿精油哪个牌子好
                            瘦腿精油哪个牌子好 1

                            好的评论是对文章的赞赏,不好的呢?可能是给人不一样的感觉

                            • xany
                              xany 0

                              学习了

                            匿名

                            发表评论

                            匿名网友
                            :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

                            拖动滑块以完成验证