WordPress自動拒絕垃圾評論

wordpress主題371,848閱讀模式

米粒在線分享:經常受到垃圾評論的滋擾,下面的代碼可能對你有所幫助。

將以下代碼粘貼到你的主題functions.php模板中。

任何包含在$ bad_comment_content數組內的字符,將會被自動拒絕留言。

  1. function in_comment_post_like($string, $array) {
  2. foreach($array as $ref) { if(strstr($string, $ref)) { returntrue; } }
  3. returnfalse;
  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');

 
  • 本文由 米粒在線 發表于 2013年6月30日20:46:07
  • 轉載請務必保留本文鏈接:http://m.bjmhhq.com/8507.html
網站建設

網站速度很慢?使用 WordPress 短時緩存(Transients)來優化數據庫查詢和 HTTP 響應!

每個人都想要一個速度很快的網站,網站速度越快,用戶停留和點擊頁面或購買產品的時間就越長,加快網站速度的方法之一是開啟緩存,而緩存背后的邏輯就是存儲信息,更具體一點說,就是找到一個比連接數據庫更快的存儲...
評論  3  訪客  3
    • 我愛卡網 1

      被垃圾評論騷擾是件頭疼的事。 :mrgreen:

      • 微歷史 3

        樓主用的是wp嗎?我看你的meta中信息都全了,我用的模板怎么就沒有呢

      發表評論

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

      拖動滑塊以完成驗證