经常受到垃圾评论的滋扰,下面的代码可能对你有所帮助。
将以下代码粘贴到你的主题functions.php模板中。
任何包含在$ bad_comment_content数组内的字符,将会被自动拒绝留言。
- function in_comment_post_like($string, $array) {
- foreach($array as $ref) { (strstr($string, $ref)) { ; } }
- ;
- }
- function drop_bad_comments() {
- (!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\’
- );
- (in_comment_post_like($lower_case_comment, $bad_comment_content)) {
- $comment_box_text = wordwrap(trim($post_comment_content), , , );
- $txtdrop = fopen(\’/var/log/httpd/wp_post-logger/nullamatix.com-text-area_dropped.txt\’, \’a\’);
- fwrite($txtdrop, . $post_comment_content . );
- fwrite($txtdrop, . $_SERVER[\’REMOTE_ADDR\’] . . date() . );
- fwrite($txtdrop, . $_SERVER[\’HTTP_USER_AGENT\’] . );
- fwrite($txtdrop, . $_SERVER[\’HTTP_REFERER\’] . );
- fwrite($txtdrop, . $_SERVER[\’SCRIPT_NAME\’] . . $_SERVER[\’REQUEST_URI\’] . );
- fwrite($txtdrop, \’————–**********——————\’.);
- header();
- header();
- header();
- wp_die( __(\’bang bang.\’) );
- }
- }
- }
- add_action(\’init\’, \’drop_bad_comments\’);
原文:http://www.wprecipes.com/automatically-refuse-spam-comments-on-your-wordpress-blog
暂无评论内容