当前位置:首页 > CMS教程 > WordPress > 列表

wordpress自动删除重复评论方法

发布:smiling 来源: PHP粉丝网  添加日期:2015-03-24 16:06:24 浏览: 评论:0 

wordpress中,已经默认加入了重复评论的限制,如果需要去掉这个限制,需要修改相应的源代码,具体如下.

wp-includes 文件夹下面 comment.php:

  1. function wp_allow_comment($commentdata) { 
  2. global $wpdb; 
  3. extract($commentdata, EXTR_SKIP); 
  4. // Simple duplicate check 
  5. // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) 
  6. $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved != 'trash' AND ( comment_author = '$comment_author' "; 
  7. if ( $comment_author_email ) 
  8. $dupe .= "OR comment_author_email = '$comment_author_email' "; 
  9. $dupe .= ") AND comment_content = '$comment_content' LIMIT 1"; 
  10. // if ( $wpdb->get_var($dupe) ) { 
  11. // do_action( 'comment_duplicate_trigger', $commentdata ); 
  12. // if ( defined('DOING_AJAX') ) 
  13. // die( __('Duplicate comment detected; it looks as though you’ve already said that!') ); 
  14. // wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!') ); 
  15. // } 
  16. do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt ); 
  17. if ( isset($user_id) && $user_id) { 
  18. $userdata = get_userdata($user_id); 
  19. $user = new WP_User($user_id); 
  20. $post_author = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", $comment_post_ID)); 
  21. } 
  22. if ( isset($userdata) && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) { 
  23. // The author and the admins get respect. 
  24. $approved = 1; 
  25. } else { 
  26. // Everyone else's comments will be checked. 
  27. if ( check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type) ) 
  28. $approved = 1;//开源软件:phpfensi.com 
  29. else 
  30. $approved = 0; 
  31. if ( wp_blacklist_check($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent) ) 
  32. $approved = 'spam'; 
  33. } 
  34. $approved = apply_filters( 'pre_comment_approved', $approved, $commentdata ); 
  35. return $approved; 
  36. } 

去掉下面部分即可:

  1. // if ( $wpdb->get_var($dupe) ) { 
  2. // do_action( 'comment_duplicate_trigger', $commentdata ); 
  3. // if ( defined('DOING_AJAX') ) 
  4. // die( __('Duplicate comment detected; it looks as though you’ve already said that!') ); 
  5. // wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!') ); 
  6. // } 

PS:修改前先记得备份哦.

Tags: wordpress重复评论 删除评论

分享到: