自动批准特定类别的帖子中的评论wordpress

  • 本文关键字:wordpress 评论 php wordpress
  • 更新时间 :
  • 英文 :


我曾使用此代码自动批准特定类别的评论,但在上次更新wordpress 4.4后,此代码不起作用:

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;
}

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

巨大的免责声明-我没有写这个解决方案。信用卡转到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插件的过滤器,因此需要激活它才能工作。

最新更新