2015-12-30 47 views
3

我曾使用此代码来自动批准特定类别的意见,但最后一次更新后,WordPress的4.4这段代码不行:自动核准特定类别的职位评论WordPress

add_filter('pre_option_comment_moderation', 'auto_aprove_posts_b'); 
add_filter('pre_option_comment_whitelist', 'auto_aprove_posts_b'); 

function auto_aprove_posts_b($option) 
{ 
    if(in_category('20')) 
    return 0; 

    return $option; 
} 

你知道如何自动批准特定类别的帖子中的评论?

+0

刚刚转载,在4.3上工作,并没有在4.4 – brasofilo

回答

0

巨大的免责声明 - 我没有写这个解决方案。积分为https://www.nosegraze.com/approve-comments-category/。她实际上回答了这个问题,所以不知道为什么答案不在这里发布。

无论如何,这将做同样的事情:

function auto_approve_comments_in_category($approved, $commentdata) { 
     $cat_id = 10; // This needs to be the ID of the category you want to approve. 

     // If the post being commented on is in our category, always approve the comment. 
     if(in_category($cat_id, $commentdata['comment_post_ID'])) { 
      return 1; 
     } 

     // Otherwise, return the original approval status. 
     return $approved; 
    } 

add_filter('pre_comment_approved' , 'auto_approve_comments_in_category' , '99', 2); 

注意,这是从Akismet在插件过滤器,以便这将需要积极进行这项工作。

相关问题