WordPress自动拒绝垃圾评论

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

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

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

  1. function in_comment_post_like($string, $array) {   
  2.     foreach($array as $ref) { (strstr($string, $ref)) {  ; } }   
  3.      ;  
  4. }  
  5. function drop_bad_comments() {  
  6.      (!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.          (in_comment_post_like($lower_case_comment, $bad_comment_content)) {  
  32.             $comment_box_text = wordwrap(trim($post_comment_content), );  
  33.             $txtdrop = fopen(\’/var/log/httpd/wp_post-logger/nullamatix.com-text-area_dropped.txt\’, \’a\’);  
  34.             fwrite($txtdrop,  . $post_comment_content . );  
  35.             fwrite($txtdrop,  . $_SERVER[\’REMOTE_ADDR\’] .  . date() . );  
  36.             fwrite($txtdrop,  . $_SERVER[\’HTTP_USER_AGENT\’] . );  
  37.             fwrite($txtdrop,  . $_SERVER[\’HTTP_REFERER\’] . );  
  38.             fwrite($txtdrop,  . $_SERVER[\’SCRIPT_NAME\’] .  . $_SERVER[\’REQUEST_URI\’] . );  
  39.             fwrite($txtdrop, \’————–**********——————\’.);  
  40.             header();  
  41.             header();  
  42.             header();  
  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

    © 版权声明
    THE END
    喜欢就支持一下吧
    点赞0 分享
    评论 抢沙发

    请登录后发表评论

      暂无评论内容