mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- code review;
This commit is contained in:
@@ -51,11 +51,11 @@ if ( ! class_exists( 'um\core\Access' ) ) {
|
||||
$this->redirect_handler = false;
|
||||
$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_action( 'pre_get_posts', array( &$this, 'exclude_posts' ), 99, 1 );
|
||||
add_action( '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_posts_args', array( &$this, 'exclude_resticted_posts_widget' ), 99, 1 );
|
||||
add_filter( 'widget_posts_args', array( &$this, 'exclude_restricted_posts_widget' ), 99, 1 );
|
||||
|
||||
//there is posts (Posts/Page/CPT) filtration if site is accessible
|
||||
//there also will be redirects if they need
|
||||
@@ -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( true );
|
||||
$exclude_posts = $this->exclude_posts_array();
|
||||
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 ) );
|
||||
@@ -1046,7 +1046,7 @@ if ( ! class_exists( 'um\core\Access' ) ) {
|
||||
* @param \WP_Comment_Query $query
|
||||
*
|
||||
*/
|
||||
function exclude_posts_comments( $query ){
|
||||
function exclude_posts_comments( $query ) {
|
||||
$exclude_posts = $this->exclude_posts_array( false );
|
||||
if ( ! empty( $exclude_posts ) ) {
|
||||
$query->query_vars['post__not_in'] = $exclude_posts;
|
||||
@@ -1057,18 +1057,19 @@ if ( ! class_exists( 'um\core\Access' ) ) {
|
||||
/**
|
||||
* get array with restricted posts
|
||||
*
|
||||
* @param boolean $in_query
|
||||
* @param bool $in_query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function exclude_posts_array( $in_query = false ) {
|
||||
function exclude_posts_array( $in_query = true ) {
|
||||
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 ( false === $in_query || ! empty( $content_restriction['_um_access_hide_from_queries'] ) ) {
|
||||
if ( $this->is_restricted( $post ) ) {
|
||||
array_push( $exclude_posts, $post );
|
||||
}
|
||||
@@ -1086,14 +1087,14 @@ if ( ! class_exists( 'um\core\Access' ) ) {
|
||||
* @param bool $in_same_term
|
||||
* @param array $excluded_terms
|
||||
* @param string $taxonomy.
|
||||
* @param WP_Post $post
|
||||
* @param \WP_Post $post
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function exclude_navigation_posts( $where, $in_same_term, $excluded_terms, $taxonomy, $post ) {
|
||||
$exclude_posts = $this->exclude_posts_array();
|
||||
if ( ! empty( $exclude_posts ) ) {
|
||||
$exclude_string = implode(',', $exclude_posts);
|
||||
$exclude_string = implode( ',', $exclude_posts );
|
||||
$where .= ' AND ID NOT IN ( ' . $exclude_string . ' )';
|
||||
}
|
||||
|
||||
@@ -1108,7 +1109,7 @@ if ( ! class_exists( 'um\core\Access' ) ) {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function exclude_resticted_posts_widget( $array ) {
|
||||
function exclude_restricted_posts_widget( $array ) {
|
||||
$exclude_posts = $this->exclude_posts_array();
|
||||
if ( ! empty( $exclude_posts ) ) {
|
||||
$array['post__not_in'] = $exclude_posts;
|
||||
|
||||
Reference in New Issue
Block a user