$title Array of QM admin panel titles. * * @return array */ public function admin_title( $title ) { return $title; } /** * Add content-control class * * @param array $classes Array of QM classes. * * @return array|string,string> */ public function admin_class( $classes ) { $classes[] = 'qm-content-control'; return $classes; } /** * Adds Memcache stats item to Query Monitor Menu * * @param array> $_menu Array of QM admin menu items. * * @return array> */ public function admin_menu( $_menu ) { $menu = []; if ( is_frontend() ) { // Insert our panel right after qm-db_queries. $menu = array_slice( $_menu, 0, 1, true ); $menu['qm-content-control'] = $this->menu( [ 'id' => 'qm-content-control', // This is the ID of the panel. 'href' => '#qm-content-control', 'title' => esc_html__( 'Content Control', 'content-control' ), ] ); $menu += array_slice( $_menu, 1, null, true ); } return $menu; } /** * Output the data. * * @return void */ public function output() { $this->before_non_tabular_output(); $this->output_global_settings(); $this->output_main_query_restrictions(); $this->output_post_restrictions(); $this->after_non_tabular_output(); } /** * Output the data. * * @return void */ public function output_global_settings() { $font_style = 'font-size: 14px!important;'; $admins_excluded = user_is_excluded(); $check_all_restrictions = apply_filters( 'content_control/check_all_restrictions', false ); // Render global settings. echo '
'; echo '

Global Settings

'; echo ''; echo ''; // Admins are excluded? echo ''; echo ''; echo ''; echo ''; // check_all_restrictions filter is enabled? echo ''; echo ''; echo ''; echo ''; echo ''; echo '
Admins Are Excluded?' . ( $admins_excluded ? 'Yes' : 'No' ) . '
Check All Restrictions Filter is Enabled?' . ( $check_all_restrictions ? 'Yes' : 'No' ) . '
'; echo '
'; } /** * Output the data. * * @return void */ public function output_main_query_restrictions() { $font_style = 'font-size: 14px!important;'; $data = $this->get_collector()->get_data(); $main_query_restrictions = isset( $data->main_query_restriction ) ? $data->main_query_restriction : null; echo '
'; echo '

Main Query

'; echo ''; echo ''; // Main query is restricted? echo ''; echo ''; echo ''; echo ''; // Main query restriction. echo ''; echo ''; echo ''; echo ''; echo ''; echo '
Main Query Is Restricted?' . ( $main_query_restrictions ? 'Yes' : 'No' ) . '
Main Query Restriction' . ( $main_query_restrictions ? '' . esc_html( $main_query_restrictions->title ) . '' : 'None' ) . '
'; echo '
'; } /** * Output the data. * * @return void */ public function output_post_restrictions() { echo '
'; echo '

Post Restrictions

'; echo ''; // Render table of each post restrictions were checked for and the results, as well as which restriction (linked) was applied. echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $data = $this->get_collector()->get_data(); $posts = isset( $data->user_can_view_content ) ? $data->user_can_view_content : []; foreach ( $posts as $post_id => $post_data ) { if ( 'main' === $post_id ) { continue; } if ( strpos( $post_data['context'], 'terms' ) !== false ) { $term = get_term( $post_id ); $name = $term->name; $type = 'TAX: ' . $term->taxonomy; } elseif ( strpos( $post_data['context'], 'posts' ) !== false ) { $post = get_post( $post_id ); $name = $post->post_title; $type = 'PT: ' . $post->post_type; } else { continue; } $user_can_view = $post_data['user_can_view'] ? 'Yes' : 'No'; $restrictions = $post_data['restrictions'] ? $post_data['restrictions'] : []; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $restrictions_html = []; foreach ( $restrictions as $restriction ) { $restrictions_html[] = '' . esc_html( $restriction->title ) . ''; } echo ''; echo ''; } echo ''; echo '
Post IDPost TitlePost TypeContextUser Can ViewRestriction
' . esc_html( $post_id ) . '' . esc_html( $name ) . '' . esc_html( $type ) . '' . esc_html( $post_data['context'] ) . '' . esc_html( $user_can_view ) . '' . wp_kses( join( ', ', $restrictions_html ), [ 'a' => [ 'href' => [], 'target' => [], ], ] ) . '
'; echo '
'; } }