From 2712cb760af48a692c45dd5e5a9bee6a111cd6f2 Mon Sep 17 00:00:00 2001 From: ashubawork <43743394+ashubawork@users.noreply.github.com> Date: Tue, 6 Jul 2021 12:55:25 +0300 Subject: [PATCH] - changed a hook for hide restricted post's comments --- includes/core/class-access.php | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/includes/core/class-access.php b/includes/core/class-access.php index c09bef14..3e2c311f 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -52,9 +52,9 @@ if ( ! class_exists( 'um\core\Access' ) ) { $this->allow_access = false; add_filter( 'pre_get_posts', array( &$this, 'exclude_posts' ), 99, 1 ); + add_filter( 'pre_get_comments', array( &$this, 'exclude_posts_comments' ), 99, 1 ); add_filter( 'get_next_post_where', array( &$this, 'exclude_navigation_posts' ), 99, 5 ); add_filter( 'get_previous_post_where', array( &$this, 'exclude_navigation_posts' ), 99, 5 ); - add_filter( 'widget_comments_args', array( &$this, 'exclude_comments_resticted_posts_widget' ), 99, 1 ); add_filter( 'widget_posts_args', array( &$this, 'exclude_resticted_posts_widget' ), 99, 1 ); //there is posts (Posts/Page/CPT) filtration if site is accessible @@ -1040,6 +1040,20 @@ if ( ! class_exists( 'um\core\Access' ) ) { } + /** + * Exclude comments from restricted posts in widgets + * + * @param \WP_Comment_Query $query + * + */ + function exclude_posts_comments( $query ){ + $exclude_posts = $this->exclude_posts_array(); + if ( ! empty( $exclude_posts ) ) { + $query->query_vars['post__not_in'] = $exclude_posts; + } + } + + /** * Exclude posts from next, previous navigation * @@ -1062,23 +1076,6 @@ if ( ! class_exists( 'um\core\Access' ) ) { } - /** - * Exclude comments from restricted posts in widgets - * - * @param array $array - * - * @return array - */ - function exclude_comments_resticted_posts_widget( $array ) { - $exclude_posts = $this->exclude_posts_array(); - if ( ! empty( $exclude_posts ) ) { - $array['post__not_in'] = $exclude_posts; - } - - return $array; - } - - /** * Exclude restricted posts in widgets *