Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自动批准特定类别文章中的评论wordpress_Php_Wordpress - Fatal编程技术网

Php 自动批准特定类别文章中的评论wordpress

Php 自动批准特定类别文章中的评论wordpress,php,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_categ

我曾使用此代码自动批准特定类别的评论,但在上次更新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;
}
您知道如何自动批准特定类别帖子中的评论吗?

巨大的免责声明-我没有编写此解决方案。功劳归于我。她实际上回答了这个问题,所以不知道为什么答案没有贴在这里

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

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插件的过滤器,因此它需要处于活动状态才能正常工作。

刚刚复制,在4.3上使用,在4.4上没有