Make WordPress Core

Ticket #20519: validate-template-vars.diff

File validate-template-vars.diff, 3.1 KB (added by wonderboymusic, 12 years ago)
  • wp-includes/template.php

     
    8282
    8383        $templates = array();
    8484
    85         $templates[] = "author-{$author->user_nicename}.php";
    86         $templates[] = "author-{$author->ID}.php";
     85        if ( isset( $author->user_nicename ) )
     86                $templates[] = "author-{$author->user_nicename}.php";
     87        if ( isset( $author->ID ) )
     88                $templates[] = "author-{$author->ID}.php";
    8789        $templates[] = 'author.php';
    8890
    8991        return get_query_template( 'author', $templates );
     
    105107        $category = get_queried_object();
    106108
    107109        $templates = array();
    108 
    109         $templates[] = "category-{$category->slug}.php";
    110         $templates[] = "category-{$category->term_id}.php";
     110        if ( isset( $category->slug ) )
     111                $templates[] = "category-{$category->slug}.php";
     112        if ( isset( $category->term_id ) )     
     113                $templates[] = "category-{$category->term_id}.php";
    111114        $templates[] = 'category.php';
    112115
    113116        return get_query_template( 'category', $templates );
     
    130133
    131134        $templates = array();
    132135
    133         $templates[] = "tag-{$tag->slug}.php";
    134         $templates[] = "tag-{$tag->term_id}.php";
     136        if ( isset( $tag->slug ) )
     137                $templates[] = "tag-{$tag->slug}.php";
     138        if ( isset( $tag->term_id ) )   
     139                $templates[] = "tag-{$tag->term_id}.php";
    135140        $templates[] = 'tag.php';
    136141
    137142        return get_query_template( 'tag', $templates );
     
    156161 */
    157162function get_taxonomy_template() {
    158163        $term = get_queried_object();
    159         $taxonomy = $term->taxonomy;
    160 
     164       
    161165        $templates = array();
     166        if ( isset( $term->taxonomy ) ) {
     167                $taxonomy = $term->taxonomy;
     168                if ( ! empty( $term->slug ) )
     169                        $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
     170                $templates[] = "taxonomy-$taxonomy.php";
     171        }
    162172
    163         $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
    164         $templates[] = "taxonomy-$taxonomy.php";
    165173        $templates[] = 'taxonomy.php';
    166174
    167175        return get_query_template( 'taxonomy', $templates );
     
    280288
    281289        $templates = array();
    282290
    283         $templates[] = "single-{$object->post_type}.php";
     291        if ( isset( $object->post_type ) )
     292                $templates[] = "single-{$object->post_type}.php";
    284293        $templates[] = "single.php";
    285294
    286295        return get_query_template( 'single', $templates );
     
    303312 */
    304313function get_attachment_template() {
    305314        global $posts;
    306         $type = explode('/', $posts[0]->post_mime_type);
    307         if ( $template = get_query_template($type[0]) )
    308                 return $template;
    309         elseif ( $template = get_query_template($type[1]) )
    310                 return $template;
    311         elseif ( $template = get_query_template("$type[0]_$type[1]") )
    312                 return $template;
    313         else
    314                 return get_query_template('attachment');
     315       
     316        if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) {
     317                $type = explode( '/', $posts[0]->post_mime_type );
     318               
     319                if ( ! empty( $type ) ) {
     320                        if ( $template = get_query_template( $type[0] ) )
     321                                return $template;
     322                        if ( $template = get_query_template($type[1]) )
     323                                return $template;
     324                        elseif ( $template = get_query_template("$type[0]_$type[1]") )
     325                                return $template;                       
     326                }
     327        }
     328               
     329        return get_query_template('attachment');
    315330}
    316331
    317332/**