Make WordPress Core

Changeset 25386


Ignore:
Timestamp:
09/12/2013 05:31:14 AM (12 years ago)
Author:
wonderboymusic
Message:

Add sanity checks to get_*_template() functions to ensure that the return value of get_queried_object() is compatible with the assumed context.

Fixes #25291.
See #25282.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/template.php

    r25312 r25386  
    8484    if ( is_array( $post_type ) )
    8585        $post_type = reset( $post_type );
    86    
     86
    8787    $obj = get_post_type_object( $post_type );
    8888    if ( ! $obj->has_archive )
     
    104104    $templates = array();
    105105
    106     if ( $author ) {
     106    if ( is_a( $author, 'WP_User' ) ) {
    107107        $templates[] = "author-{$author->user_nicename}.php";
    108108        $templates[] = "author-{$author->ID}.php";
     
    130130    $templates = array();
    131131
    132     if ( $category ) {
     132    if ( ! empty( $category->slug ) ) {
    133133        $templates[] = "category-{$category->slug}.php";
    134134        $templates[] = "category-{$category->term_id}.php";
     
    156156    $templates = array();
    157157
    158     if ( $tag ) {
     158    if ( ! empty( $tag->slug ) ) {
    159159        $templates[] = "tag-{$tag->slug}.php";
    160160        $templates[] = "tag-{$tag->term_id}.php";
     
    187187    $templates = array();
    188188
    189     if ( $term ) {
     189    if ( ! empty( $term->slug ) ) {
    190190        $taxonomy = $term->taxonomy;
    191191        $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
     
    311311    $templates = array();
    312312
    313     if ( $object )
     313    if ( ! empty( $object->post_type ) )
    314314        $templates[] = "single-{$object->post_type}.php";
    315315    $templates[] = "single.php";
     
    342342            if ( $template = get_query_template( $type[0] ) )
    343343                return $template;
    344             elseif ( $template = get_query_template( $type[1] ) )
    345                 return $template;
    346             elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
    347                 return $template;
     344            elseif ( ! empty( $type[1] ) ) {
     345                if ( $template = get_query_template( $type[1] ) )
     346                    return $template;
     347                elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
     348                    return $template;
     349            }
    348350        }
    349351    }
Note: See TracChangeset for help on using the changeset viewer.