WordPress.org

Making WordPress.org


Ignore:
Timestamp:
05/26/2016 10:44:58 PM (4 years ago)
Author:
coffee2code
Message:

Handbook plugin: Permit use of wporg_is_handbook() without warnings before main query runs.

Props keesiemeijer.
Fixes #1731.

File:
1 edited

Legend:

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

    r3235 r3262  
    3838
    3939    foreach ( $post_types as $post_type ) {
    40         $is_handbook    = ! $handbook || ( $handbook === $post_type );
    41         $handbook_query = is_singular( $post_type ) || is_post_type_archive( $post_type );
     40        $is_handbook     = ! $handbook || ( $handbook === $post_type );
     41        $single_handbook = false;
     42
     43        if ( is_singular() ) {
     44            $queried_obj = get_queried_object();
     45
     46            if ( $queried_obj ) {
     47                $single_handbook = is_singular( $post_type );
     48            } else {
     49                // Queried object is not set, use the post type query var.     
     50                $qv_post_type = get_query_var( 'post_type' );
     51
     52                if ( is_array( $qv_post_type ) ) {
     53                    $qv_post_type = reset( $qv_post_type );
     54                }
     55
     56                $single_handbook = ( $post_type === $qv_post_type );
     57            }
     58        }
     59
     60        $handbook_query = $single_handbook || is_post_type_archive( $post_type );
    4261
    4362        if ( $is_handbook && $handbook_query ) {
Note: See TracChangeset for help on using the changeset viewer.