- fixed restricted posts for comments

This commit is contained in:
ashubawork
2021-07-06 13:50:51 +03:00
parent 2712cb760a
commit b021a2e881
+27 -25
View File
@@ -1031,7 +1031,7 @@ if ( ! class_exists( 'um\core\Access' ) ) {
*/
function exclude_posts( $query ) {
if ( $query->is_main_query() ) {
$exclude_posts = $this->exclude_posts_array();
$exclude_posts = $this->exclude_posts_array( true );
if ( ! empty( $exclude_posts ) ) {
$post__not_in = $query->get( 'post__not_in', array() );
$query->set( 'post__not_in', array_merge( $post__not_in, $exclude_posts ) );
@@ -1047,13 +1047,38 @@ if ( ! class_exists( 'um\core\Access' ) ) {
*
*/
function exclude_posts_comments( $query ){
$exclude_posts = $this->exclude_posts_array();
$exclude_posts = $this->exclude_posts_array( false );
if ( ! empty( $exclude_posts ) ) {
$query->query_vars['post__not_in'] = $exclude_posts;
}
}
/**
* get array with restricted posts
*
* @param boolean $in_query
*
* @return array
*/
function exclude_posts_array( $in_query = false ) {
global $wpdb;
$exclude_posts = array();
$posts = $wpdb->get_col("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'um_content_restriction'");
foreach ( $posts as $post ) {
$content_restriction = $this->get_post_privacy_settings( $post );
if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) || $in_query === false ) {
if ( $this->is_restricted( $post ) ) {
array_push( $exclude_posts, $post );
}
}
}
return $exclude_posts;
}
/**
* Exclude posts from next, previous navigation
*
@@ -1093,29 +1118,6 @@ if ( ! class_exists( 'um\core\Access' ) ) {
}
/**
* get array with restricted posts
*
*/
function exclude_posts_array() {
global $wpdb;
$exclude_posts = array();
$posts = $wpdb->get_col("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'um_content_restriction'");
foreach ( $posts as $post ) {
$content_restriction = $this->get_post_privacy_settings( $post );
if ( ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
if ( $this->is_restricted( $post ) ) {
array_push( $exclude_posts, $post );
}
}
}
return $exclude_posts;
}
/**
* @param string $single_template
*