Making WordPress.org


Ignore:
Timestamp:
07/20/2016 04:41:16 PM (10 years ago)
Author:
coffee2code
Message:

Handbook plugin: Allow wporg_is_handbook() to accept an array of handbook post types.

File:
1 edited

Legend:

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

    r3263 r3698  
    2727 * Is the query for an existing handbook page?
    2828 *
    29  * @param string  $handbook Handbook post type.
    30  * @return bool             Whether the query is for an existing handbook page. Returns true on handbook pages.
     29 * @param string|array  $handbook Handbook post type(s).
     30 * @return bool         Whether the query is for an existing handbook page. Returns true on handbook pages.
    3131 */
    3232function wporg_is_handbook( $handbook = '' ) {
    3333        $post_types = wporg_get_handbook_post_types();
     34        if ( ! is_array( $handbook ) ) {
     35                $handbook = $handbook ? (array) $handbook : array();
     36        }
    3437
    3538        if ( is_admin() || ! $post_types ) {
     
    3841
    3942        foreach ( $post_types as $post_type ) {
    40                 $is_handbook     = ! $handbook || ( $handbook === $post_type );
    41                 $single_handbook = false;
     43                // Skip unless checking for all handbooks or for the specified handbook(s).
     44                if ( $handbook && ! in_array( $post_type, $handbook ) ) {
     45                        continue;
     46                }
    4247
    43                 if ( is_singular() ) {
     48                $handbook_query = is_post_type_archive( $post_type ) || get_query_var( 'is_handbook_root' );
     49
     50                if ( ! $handbook_query && is_singular() ) {
    4451                        $queried_obj = get_queried_object();
    4552
    4653                        if ( $queried_obj ) {
    47                                 $single_handbook = is_singular( $post_type );
     54                                $handbook_query = is_singular( $post_type );
    4855                        } else {
    49                                 // Queried object is not set, use the post type query var.             
     56                                // Queried object is not set, use the post type query var.
    5057                                $qv_post_type = get_query_var( 'post_type' );
    5158
     
    5461                                }
    5562
    56                                 $single_handbook = ( $post_type === $qv_post_type );
     63                                $handbook_query = ( $post_type === $qv_post_type );
    5764                        }
    5865                }
    5966
    60                 $handbook_query = $single_handbook || is_post_type_archive( $post_type );
    61 
    62                 if ( $is_handbook && $handbook_query ) {
     67                if ( $handbook_query ) {
    6368                        return true;
    6469                }
Note: See TracChangeset for help on using the changeset viewer.