WordPress自动拒绝垃圾评论

  • 时间:
  • 浏览:1
  • 来源:5分排列3官网平台_5分排列3网投平台_5分排列3投注平台_5分排列3娱乐平台
作者:匿名 hihi 来源: 浏览: 2013-7-4 14:10:41 字号:大 中 小

[摘要]今天的wordpress教程,教朋友的是怎样才能自动拒绝垃圾评论。主要通过修改functions.php文件来实现。

  总爱受到垃圾评论的滋扰,下面的代码已经对你有所帮助。

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

  任何含高在$ bad_comment_content数组内的字符,已经被自动拒绝留言。

function in_comment_post_like($string, $array) {    

foreach($array as $ref) { if(strstr($string, $ref)) { return true; } }

return false;

}

function drop_bad_comments() {

if (!empty($_POST['comment'])) {

$post_comment_content = $_POST['comment'];

$lower_case_comment = strtolower($_POST['comment']);

$bad_comment_content = array(

'viagra',

'hydrocodone',

'hair loss',

'xanax',

'tramadol',

'russian girls',

'russian brides',

'lorazepam',

'adderall',

'dexadrine',

'no prescription',

'oxycontin',

'without a prescription',

'sex pics',

'family incest',

'online casinos',

'online dating',

'cialis',

'best forex',

'amoxicillin'

);

if (in_comment_post_like($lower_case_comment, $bad_comment_content)) {

$comment_box_text = wordwrap(trim($post_comment_content), 500, "\n ", true);

$txtdrop = fopen('/var/log/httpd/wp_post-logger/nullamatix.com-text-area_dropped.txt', 'a');

fwrite($txtdrop, " --------------\n [COMMENT] = " . $post_comment_content . "\n --------------\n");

fwrite($txtdrop, " [SOURCE_IP] = " . $_SERVER['REMOTE_ADDR'] . " @ " . date("F j, Y, g:i a") . "\n");

fwrite($txtdrop, " [USERAGENT] = " . $_SERVER['HTTP_USER_AGENT'] . "\n");

fwrite($txtdrop, " [REFERER ] = " . $_SERVER['HTTP_REFERER'] . "\n");

fwrite($txtdrop, " [FILE_NAME] = " . $_SERVER['SCRIPT_NAME'] . " - [REQ_URI] = " . $_SERVER['REQUEST_URI'] . "\n");

fwrite($txtdrop, '--------------**********------------------'."\n");

header("HTTP/1.1 406 Not Acceptable");

header("Status: 406 Not Acceptable");

header("Connection: Close");

wp_die( __('bang bang.') );

}

}

}

add_action('init', 'drop_bad_comments');

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

sssss
Tags: WordPress   WordPress教程   评论  
责任编辑:lsw16