Making WordPress.org

Changeset 3697


Ignore:
Timestamp:
07/20/2016 04:40:34 PM (8 years ago)
Author:
coffee2code
Message:

Handbook plugin: Add 'is_handbook_root' query var instead of allowing the handbook root page to also be seen as a post type archive.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php

    r3689 r3697  
    123123        add_action( 'template_redirect',                  array( $this, 'redirect_handbook_root_page' ) );
    124124        add_filter( 'template_include',                   array( $this, 'template_include' ) );
     125        add_filter( 'query_vars',                         array( $this, 'add_query_vars' ) );
    125126        add_filter( 'pre_get_posts',                      array( $this, 'pre_get_posts' ) );
    126127        add_action( 'widgets_init',                       array( $this, 'handbook_sidebar' ), 11 ); // After P2
     
    267268        if ( is_singular( $this->post_type )
    268269            &&
    269             ! is_post_type_archive( $this->post_type )
     270            ! get_query_var( 'is_handbook_root' )
    270271            &&
    271272            in_array( get_query_var( 'name' ), array( $this->post_type, substr( $this->post_type, 0, -9 ) ) )
     
    293294        }
    294295        // For handbook landing page.
    295         elseif ( is_post_type_archive( $this->post_type ) ) {
     296        elseif ( get_query_var( 'is_handbook_root' ) && get_query_var( 'handbook' ) === $this->post_type ) {
    296297            if ( 'handbook' !== $this->post_type ) {
    297298                $handbook_templates[] = "single-{$this->post_type}.php";
     
    307308
    308309        return $template;
     310    }
     311
     312    /**
     313     * Add public query vars for handbooks.
     314     *
     315     * @param array  $public_query_vars The array of whitelisted query variables.
     316     * @return array Array with public query vars.
     317     */
     318    function add_query_vars( $public_query_vars ) {
     319        $public_query_vars['is_handbook_root'] = false;
     320
     321        return $public_query_vars;
    309322    }
    310323
     
    319332            if ( $page ) {
    320333                $query->set( 'p', $page->ID );
    321                 $query->is_singular = true;
     334                $query->set('is_handbook_root', true );
     335
     336                $query->is_archive           = false;
     337                $query->is_post_type_archive = false;
     338                $query->is_single            = true;
     339                $query->is_singular          = true;
    322340            }
    323341            $query->set( 'handbook', $this->post_type );
Note: See TracChangeset for help on using the changeset viewer.