很多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以其开源易用的特点以及宏大的格调插件数据库支持,曾经成了以后最盛行的博客零碎!而博客又以其良...
明天在修正网站的时分,不小心把最新版Wordpress3.5.1的wp-includes目录下的functions.php笼罩出来了,招致...
在 WordPress 中加载脚本(为 CSS 和 JS,下同)文件,大少数人的做法是间接在 header.php 文件中增加 link...
最近发现 有不少文章配上图片,写得比拟长。这样会招致页面加载速渡过慢,不利于用户体验。尤其是新增加的 ...