WordPress完成主动回绝渣滓评论的办法

很多WordPress站长都常常遭到渣滓评论的滋扰,针对这种状况,采纳上面的代码可能会对你有所协助。
将以下代码退出到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), 80, "\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');

以上就是安达网络工作室关于《WordPress实现自动拒绝垃圾评论的方法》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: WordPress 自动拒绝 垃圾评论
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
wordpress正当利用wp-config.php文件小性能

这里有几个经过往wp-config.php中增加代码完成相干性能的技巧分享给大家。 1,去掉WordPress的历史修订版本...

Wordpress 企业网站的四点益处

Wordpress以其开源易用的特点以及宏大的格调插件数据库支持,曾经成了以后最盛行的博客零碎!而博客又以其良...

简略理解WordPress开发中update_option()函数的用法

函数引见 update_option()用于更新数据表中存在的选项值。该函数可取代add_option,但不迭add_option灵敏。...

WordPress伪动态和中文标签支持配置办法

WORDPRESS博客站曾经运转快一年了,在伪动态上不断很纠结,空间默许不支持伪动态,网上找了很多办法,用404...

利用jQuery完成WordPress中@的ID悬浮显示评论内容

比方: A 留言了, B 用 @ 回复了 A, 所以 B 的回复可能是这样的: @A How much money do you have? 就是说...

wordpress去掉自带的logo或许左侧栏的菜双方法

去掉logo或许左侧栏的菜单,避免被改掉。 在应用模板下的functions.php下修正 复制代码代码如下: function ...

需求提交

客服服务