From 249406e826d367df3065546140f403d9bc9c878d Mon Sep 17 00:00:00 2001 From: ashubawork <43743394+ashubawork@users.noreply.github.com> Date: Wed, 7 Jul 2021 13:39:05 +0300 Subject: [PATCH] - exclude restricted post's comments from a comments feed --- includes/core/class-access.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 39e38023..c53f4ae3 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -56,6 +56,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { 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_posts_args', array( &$this, 'exclude_restricted_posts_widget' ), 99, 1 ); + add_filter( 'comment_feed_where', array( &$this, 'exclude_posts_comments_feed' ), 99, 2 ); //there is posts (Posts/Page/CPT) filtration if site is accessible //there also will be redirects if they need @@ -1054,6 +1055,25 @@ if ( ! class_exists( 'um\core\Access' ) ) { } + /** + * Exclude comments from comments feed + * + * @param string $where + * @param \WP_Query $query + * + * @return string + */ + function exclude_posts_comments_feed( $where, $query ){ + $exclude_posts = $this->exclude_posts_array( false ); + if ( ! empty( $exclude_posts ) ) { + $exclude_string = implode( ',', $exclude_posts ); + $where .= ' AND comment_post_ID NOT IN ( ' . $exclude_string . ' )'; + } + + return $where; + } + + /** * get array with restricted posts *