Добрый день еще раз.
Сейчас я в настройках Ultimate выбираю "полное скрытие" записей (ни заголовка, ничего не видно) из ленты для юзеров, не оплативших доступ. Но в виджетах темы эти записи все равно видны.
Могли бы вы помочь поправить код виджетов моей темы?
Какую часть кода необходимо прислать? Вот так выглядит описание одного из виджетов в файле widgets.php (если это не то, что нужно, подскажите, код какого файла приложить):
if( !class_exists( 'Gazeta_Related_Posts' ) ){ /** * Related Posts Widget. * @author ADMIN * */ class Gazeta_Related_Posts extends WP_Widget{ function Gazeta_Related_Posts() { parent::__construct( 'gazeta-related-posts', // Base ID __('Gazeta Related Posts', 'gazeta'), // Name array( 'description' => __('Display the Related Posts', 'gazeta')) // Args ); } function widget($args, $instance){ if( ! is_single() ){ return;// nothing will be shown here. } wp_reset_postdata(); $current_post_tags = $current_post_categories = null; $current_post = get_the_ID(); $title = !empty( $instance['title'] ) ? apply_filters('widget_title', esc_attr( $instance['title'] ) ) : null; $layout = isset( $instance['layout'] ) ? esc_attr( $instance['layout'] ) : 'vertical'; $columns = isset( $instance['columns'] ) ? esc_attr( $instance['columns'] ) : '2'; $thumbnail_size = isset( $instance['thumbnail_size'] ) ? esc_attr( $instance['thumbnail_size'] ) : 'image-370-252'; $post_format = isset( $instance['post_format'] ) ? esc_attr( $instance['post_format'] ) : 'on'; $author__in = isset( $instance['author__in'] ) ? esc_attr( $instance['author__in'] ) : ''; $sticky = isset( $instance['ignore_sticky_posts'] ) ? esc_attr( $instance['ignore_sticky_posts'] ) : 'on'; $orderby = isset( $instance['orderby'] ) ? esc_attr( $instance['orderby'] ) : 'ID'; $order = isset( $instance['order'] ) ? esc_attr( $instance['order'] ) : 'DESC'; $filter_condition = isset( $instance['filter_condition'] ) ? esc_attr( $instance['filter_condition'] ) : 'post_tag'; $posts_per_page = isset( $instance['posts_per_page'] ) ? absint( $instance['posts_per_page'] ) : 3; if( function_exists( 'gazeta_get_post_terms' ) ){ $current_post_tags = gazeta_get_post_terms( $current_post , 'post_tag'); $current_post_categories = gazeta_get_post_terms( $current_post , 'category'); } $post_data = array( 'no_found_rows' => true, 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'orderby' => ( $orderby == 'view' ) ? 'meta_value_num' : $orderby, 'order' => $order, 'post__not_in' => array( $current_post ) // Do not include the current post. ); if( !empty( $author__in ) ){ $author__in = explode(",", $author__in); if( is_array( $author__in ) && !empty( $author__in ) ){ $post_data['author__in'] = $author__in; } } // order by views if( $orderby == 'view' ){ $post_data['meta_key'] = GAZETA_POST_VIEWS_FIELD_NAME; } $comment_type = gazeta_get_comment_type_support(); if( !empty( $comment_type ) && $orderby == 'comment_count' ){ $post_data['orderby'] = 'meta_value_num'; $post_data['meta_key'] = GAZETA_POST_FACEBOOK_COMMENTS_FIELD_NAME; } // Post formats if( !empty( $post_format ) ){ $post_format = explode(",", $post_format); if( is_array( $post_format ) && !empty( $post_format ) ){ $post_data['tax_query'][] = array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => $post_format, 'operator' => 'IN' ); } } // $sticky if( $sticky == 'on' ){ $post_data['ignore_sticky_posts'] = true; } // filter. if( $filter_condition == 'all' ){ if( isset( $current_post_categories ) ){ $post_data['category__in'] = $current_post_categories; } if( isset( $current_post_tags ) ){ $post_data['tag__in'] = $current_post_tags; } } if( $filter_condition == 'category' ){ if( isset( $current_post_categories ) ){ $post_data['category__in'] = $current_post_categories; } } if( $filter_condition == 'post_tag' ){ if( isset( $current_post_tags ) ){ $post_data['tag__in'] = $current_post_tags; } } $post_data = apply_filters( 'gazeta_related_post/args' , $post_data, $this->id); $post_query = wp_cache_get( $this->id ); if( $post_query === false ){ $post_query = new WP_Query( $post_data ); } wp_cache_set( $this->id , $post_query, '', 300); $grid_columns = function_exists( 'gazeta_get_bt_grid_columns' ) ? gazeta_get_bt_grid_columns( $columns ) : 12; if( $post_query->have_posts() ): ?> <div class="related-posts related-posts-<?php print $layout;?>"> <?php if( !empty( $title ) ):?> <h5 class="related-widget-title"><?php print $title;?></h5> <?php endif;?> <ul> <?php while ( $post_query->have_posts() ) : $post_query->the_post();?> <?php if( $layout == 'vertical' ):?> <li <?php post_class( 'related-post-item-' .$layout )?>> <div class="col-md-3 post-date-section"> <div class="rp-date"> <span><?php print get_the_date( apply_filters( 'gazeta_post_meta/month' , 'F') );?></span> <?php print get_the_date( apply_filters( 'gazeta_post_meta/date' , 'd') );?> <span><em>/</em> <?php print get_the_date( apply_filters( 'gazeta_post_meta/year' , 'Y') );?></span> </div> </div> <div class="col-md-9 post-content-section"> <?php if( has_post_thumbnail( get_the_ID() ) ){ print '<div class="related-thumbnail-image">'; print '<a href="'.get_permalink().'">'; print get_the_post_thumbnail( get_the_ID(), apply_filters( 'gazeta_related_post/thumbnail_size' , 'medium', $layout, $columns) , array( 'class'=>'img-responsive' ) ); if( get_post_format( get_the_ID() ) == 'video' ){ print '<div class="video-format-img-hover"></div>'; } print '</a>'; print '</div>'; } else{ echo '<div class="post-content">'; the_excerpt(); echo '</div>'; } ?> <div class="rp-inner <?php if( !has_post_thumbnail( get_the_ID() ) ):?>no-thumbnail-image<?php endif;?>"> <?php the_title( '<h4 class="related-post-title"><a href="'.get_permalink( get_the_ID() ).'">','</a></h4>' );?> <?php print gazeta_the_post_extra_metas( get_the_ID() );?> <a href="<?php the_permalink()?>" class="rp-more"><?php _e( 'Read more <em>→</em>','gazeta' );?></a> </div> </div> </li> <?php else:?> <li <?php post_class( 'related-post-item-'.$layout.' reponsive-height col-sm-'.$grid_columns.' col-xs-6' )?>> <div class="iv-inner"> <?php if( has_post_thumbnail( get_the_ID() ) ):?> <div class="iv-main"> <?php print '<a href="'.get_permalink().'">'; print get_the_post_thumbnail( get_the_ID(), apply_filters( 'gazeta_related_post/thumbnail_size' , $thumbnail_size, $layout, $columns) , array( 'class'=>'img-responsive' ) ); if( get_post_format( get_the_ID() ) == 'video' ){ print '<div class="video-format-img-hover"></div>'; } print '</a>'; ?> </div> <?php endif;?> <?php if( has_category('', get_the_ID()) ):?> <span class="iv-cat"><?php print get_the_category_list(', ')?></span> <?php endif;?> <h5 class="related-post-title"><a href="<?php the_permalink()?>"><?php the_title();?></a></h5> <?php print gazeta_the_post_extra_metas( get_the_ID() );?> </div> </li> <?php endif;?> <?php endwhile;?> </ul> </div> <?php endif; wp_reset_postdata(); } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = esc_attr( $new_instance['title'] ); $instance['layout'] = esc_attr( $new_instance['layout'] ); $instance['columns'] = esc_attr( $new_instance['columns'] ); $instance['thumbnail_size'] = esc_attr( $new_instance['thumbnail_size'] ); $instance['post_format'] = esc_attr( $new_instance['post_format'] ); $instance['author__in'] = esc_attr( $new_instance['author__in'] ); $instance['ignore_sticky_posts']= esc_attr( $new_instance['ignore_sticky_posts'] ); $instance['orderby'] = esc_attr( $new_instance['orderby'] ); $instance['order'] = esc_attr( $new_instance['order'] ); $instance['filter_condition'] = esc_attr( $new_instance['filter_condition'] ); $instance['posts_per_page'] = absint( $new_instance['posts_per_page'] ); return $instance; } function form( $instance ){ $defaults = array( 'title' => __('Related Post', 'gazeta'), 'layout' => 'vertical', 'columns' => '2', 'thumbnail_size' => 'image-370-252', 'post_format' => '', 'author__in' => '', 'ignore_sticky_posts' => 'on', 'category' => '', 'orderby' => 'ID', 'order' => 'DESC', 'filter_condition' => 'post_tag', 'posts_per_page' => 3, ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'title' ));?>"><?php _e('Title:', 'gazeta');?></label> <input id="<?php echo esc_attr( $this->get_field_id( 'title' ));?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) );?>" value="<?php echo esc_attr( $instance['title'] );?>" style="width:100%;" /> </p> <p> <label for="<?php echo $this->get_field_id( 'layout' ); ?>"><?php _e('Layout:', 'gazeta'); ?></label> <select style="width:100%;" id="<?php echo $this->get_field_id( 'layout' ); ?>" name="<?php echo $this->get_field_name( 'layout' ); ?>"> <?php foreach ( $this->layout() as $key=>$value ){ ?> <option <?php selected( $key , esc_attr( $instance['layout'] ))?> value="<?php print $key;?>"><?php print $value;?></option> <?php } ?> </select> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'columns' ));?>"><?php _e('Columns:', 'gazeta');?></label> <input id="<?php echo esc_attr( $this->get_field_id( 'columns' ));?>" name="<?php echo esc_attr( $this->get_field_name( 'columns' ) );?>" value="<?php echo esc_attr( $instance['columns'] );?>" style="width:100%;" /> <small><?php _e('This option is only available for <strong>Horizon</strong> layout','gazeta')?></small> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'thumbnail_size' ));?>"><?php _e('Thumbnail Size:', 'gazeta');?></label> <input id="<?php echo esc_attr( $this->get_field_id( 'thumbnail_size' ));?>" name="<?php echo esc_attr( $this->get_field_name( 'thumbnail_size' ) );?>" value="<?php echo esc_attr( $instance['thumbnail_size'] );?>" style="width:100%;" /> <small><?php _e('This option is only available for <strong>Horizon</strong> layout','gazeta')?></small> <small><?php printf(__( 'Enter image size. Example: "thumbnail", "medium", "large", "full" or other sizes defined by current theme size: <strong>%s</strong>".', 'gazeta' ), implode(", ", gazeta_get_thumbnail_image_sizes()) )?></small> </p> <p> <label for="<?php echo $this->get_field_id( "post_format" ); ?>"><?php _e( 'Post Format','gazeta' ); ?></label> <input id="<?php echo $this->get_field_id( "post_format" ); ?>" name="<?php echo $this->get_field_name( "post_format" ); ?>" type="text" value="<?php echo esc_attr( $instance["post_format"] ); ?>" style="width:100%;"/> <small><?php _e('Specify Post Format to retrieve (post-format-standard, post-format-audio, post-format-gallery,post-format-image,post-format-video), leave blank for all.','gazeta')?></small> </p> <p> <label for="<?php echo $this->get_field_id( "author__in" ); ?>"><?php _e( 'Author','gazeta' ); ?></label> <input id="<?php echo $this->get_field_id( "author__in" ); ?>" name="<?php echo $this->get_field_name( "author__in" ); ?>" type="text" value="<?php echo esc_attr( $instance["author__in"] ); ?>" style="width:100%;"/> <small><?php _e('Specify Author to retrieve, use author id, separated by comma(,)','gazeta')?></small> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'ignore_sticky_posts' ));?>"><?php _e('Ignore Sticky Posts:', 'gazeta');?></label> <input <?php checked( 'on' , esc_attr( $instance['ignore_sticky_posts'] ), true);?> type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'ignore_sticky_posts' ));?>" name="<?php echo esc_attr( $this->get_field_name( 'ignore_sticky_posts' ) );?>"/> </p> <?php if( function_exists( 'gazeta_post_orderby' ) ):?> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"><?php _e('Order by:', 'gazeta'); ?></label> <select style="width:100%;" id="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'orderby' ) ); ?>"> <?php foreach ( gazeta_post_orderby() as $key=>$value ){ ?> <option <?php selected( esc_attr( $instance['orderby'] ) , esc_attr( $key ), true);?> value="<?php print esc_attr( $key );?>"><?php print esc_attr( $value );?></option> <?php } ?> </select> </p> <?php endif;?> <?php if( function_exists( 'gazeta_post_order' ) ):?> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"><?php _e('Order:', 'gazeta'); ?></label> <select style="width:100%;" id="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'order' ) ); ?>"> <?php foreach ( gazeta_post_order() as $key=>$value ){ ?> <option <?php selected( esc_attr( $instance['order'] ) , esc_attr( $key ), true);?> value="<?php print esc_attr( $key );?>"><?php print esc_attr( $value );?></option> <?php } ?> </select> </p> <?php endif;?> <p> <label for="<?php echo $this->get_field_id( 'filter_condition' ); ?>"><?php _e('Filter Condition:', 'gazeta'); ?></label> <select style="width:100%;" id="<?php echo $this->get_field_id( 'filter_condition' ); ?>" name="<?php echo $this->get_field_name( 'filter_condition' ); ?>"> <?php foreach ( $this->condition() as $key=>$value ){ ?> <option <?php selected( $key , esc_attr( $instance['filter_condition'] ))?> value="<?php print $key;?>"><?php print $value;?></option> <?php } ?> </select> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'posts_per_page' ) ); ?>"><?php _e('Show Posts:', 'gazeta'); ?></label> <input id="<?php echo esc_attr( $this->get_field_id( 'posts_per_page' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'posts_per_page' ) ); ?>" value="<?php echo esc_attr( $instance['posts_per_page'] ); ?>" style="width:100%;" /> </p> <?php } function condition(){ return array( 'all' => __('Category and Post Tag','gazeta'), 'category' => __('Category Only','gazeta'), 'post_tag' => __('Post Tag Only','gazeta') ); } function layout(){ return array( 'vertical' => __('Vertical','gazeta'), 'horizon' => __('Horizon','gazeta') ); } } }
весь код виджета не нужен, вывод контента виджета формируется в методе widget(), поэтому в качестве какого то универсального решения можно предложить искать внутри нужного виджета объявление этого метода:
function widget(){ ... }
и прописать в начале этого метода проверку определенного доступа у текущего пользователя, за основу можно взять код предложенный в описании дополнения на проверку доступа:
<?php global $WAU_User; //идентификаторы доступа, //которыми закрываем контент $account_ids = array(1,3); //соответствие доступа $important = 0; //1 if($WAU_User->is_branch_access($account_ids, $important)){ echo 'Показываем скрытый контент'; }else{ echo 'Доступа нет, контент закрыт'; //можем вывести карточку доступа echo wau_get_accounts_box($account_ids); } ?>
можем применить его внутри метода widget и получим примерно следующее:
function widget(){ global $WAU_User; //идентификаторы доступа, //которыми закрываем контент $account_ids = array(1,3); //соответствие доступа $important = 0; //1 if(!$WAU_User->is_branch_access($account_ids, $important)) return false; ... }
укажите свои идентификаторы доступа в массиве
$account_ids = array(1,3);
Андрей, я пока только погружаюсь внутрь, поэтому прошу посмотреть, правильно ли добавлен код (нет ли не хватающих скоб и т.д.).
Я просто взял Ваш код и добавил его в тот длинный код, что я опубликовал выше:
- скрин
Добавил так в два виджета. Изменений нет. Записи по-прежнему видны.
код добавлен неверный, надо читать инструкцию до конца, удалите его, в вашем случае, для исключения закрытых записей надо разместить предложенный ниже код в файл функций темы:
add_filter('gazeta_related_post/args', 'exclude_wau_related_posts'); function exclude_wau_related_posts($postdata){ global $WAU_User; if($hidden_posts = $WAU_User->get_hidden_posts()){ $postdata['post__not_in'] = $hidden_posts; } return $postdata; }
Андрей, из файла widget.php всё убрал. Вернул в исходное состояние. Добавил код из предыдущего сообщения в файл functions.php в конце файла - сразу после блока, скрывающего комментарии.
Скрин -
Записи в виджетах все равно всем видны.