Avoid notices in get_*_template() functions that use get_queried_object(), which can return null. Props wonderboymusic. fixes #20519
git-svn-id: https://develop.svn.wordpress.org/trunk@22293 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a5d0972890
commit
5108ff8b1e
@ -82,8 +82,10 @@ function get_author_template() {
|
||||
|
||||
$templates = array();
|
||||
|
||||
$templates[] = "author-{$author->user_nicename}.php";
|
||||
$templates[] = "author-{$author->ID}.php";
|
||||
if ( $author ) {
|
||||
$templates[] = "author-{$author->user_nicename}.php";
|
||||
$templates[] = "author-{$author->ID}.php";
|
||||
}
|
||||
$templates[] = 'author.php';
|
||||
|
||||
return get_query_template( 'author', $templates );
|
||||
@ -106,8 +108,10 @@ function get_category_template() {
|
||||
|
||||
$templates = array();
|
||||
|
||||
$templates[] = "category-{$category->slug}.php";
|
||||
$templates[] = "category-{$category->term_id}.php";
|
||||
if ( $category ) {
|
||||
$templates[] = "category-{$category->slug}.php";
|
||||
$templates[] = "category-{$category->term_id}.php";
|
||||
}
|
||||
$templates[] = 'category.php';
|
||||
|
||||
return get_query_template( 'category', $templates );
|
||||
@ -130,8 +134,10 @@ function get_tag_template() {
|
||||
|
||||
$templates = array();
|
||||
|
||||
$templates[] = "tag-{$tag->slug}.php";
|
||||
$templates[] = "tag-{$tag->term_id}.php";
|
||||
if ( $tag ) {
|
||||
$templates[] = "tag-{$tag->slug}.php";
|
||||
$templates[] = "tag-{$tag->term_id}.php";
|
||||
}
|
||||
$templates[] = 'tag.php';
|
||||
|
||||
return get_query_template( 'tag', $templates );
|
||||
@ -156,12 +162,14 @@ function get_tag_template() {
|
||||
*/
|
||||
function get_taxonomy_template() {
|
||||
$term = get_queried_object();
|
||||
$taxonomy = $term->taxonomy;
|
||||
|
||||
$templates = array();
|
||||
|
||||
$templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
|
||||
$templates[] = "taxonomy-$taxonomy.php";
|
||||
if ( $term ) {
|
||||
$taxonomy = $term->taxonomy;
|
||||
$templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
|
||||
$templates[] = "taxonomy-$taxonomy.php";
|
||||
}
|
||||
$templates[] = 'taxonomy.php';
|
||||
|
||||
return get_query_template( 'taxonomy', $templates );
|
||||
@ -280,7 +288,8 @@ function get_single_template() {
|
||||
|
||||
$templates = array();
|
||||
|
||||
$templates[] = "single-{$object->post_type}.php";
|
||||
if ( $object )
|
||||
$templates[] = "single-{$object->post_type}.php";
|
||||
$templates[] = "single.php";
|
||||
|
||||
return get_query_template( 'single', $templates );
|
||||
@ -303,15 +312,21 @@ function get_single_template() {
|
||||
*/
|
||||
function get_attachment_template() {
|
||||
global $posts;
|
||||
$type = explode('/', $posts[0]->post_mime_type);
|
||||
if ( $template = get_query_template($type[0]) )
|
||||
return $template;
|
||||
elseif ( $template = get_query_template($type[1]) )
|
||||
return $template;
|
||||
elseif ( $template = get_query_template("$type[0]_$type[1]") )
|
||||
return $template;
|
||||
else
|
||||
return get_query_template('attachment');
|
||||
|
||||
if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) {
|
||||
$type = explode( '/', $posts[0]->post_mime_type );
|
||||
|
||||
if ( ! empty( $type ) ) {
|
||||
if ( $template = get_query_template( $type[0] ) )
|
||||
return $template;
|
||||
elseif ( $template = get_query_template( $type[1] ) )
|
||||
return $template;
|
||||
elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
||||
return get_query_template( 'attachment' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user