From 0b09ec156f46593730850a373df769fea89457a4 Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 12 Sep 2010 18:46:18 +0000 Subject: [PATCH] Apply filters consistently in get_*_template() functions. Fixes #14310 git-svn-id: https://develop.svn.wordpress.org/trunk@15611 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/theme.php | 62 ++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index c5ab2cd40d..fdeb3543af 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -687,32 +687,28 @@ function get_theme_root_uri( $stylesheet_or_template = false ) { } /** - * Retrieve path to file without the use of extension. + * Retrieve path to a template * - * Used to quickly retrieve the path of file without including the file - * extension. It will also check the parent template, if the file exists, with - * the use of {@link locate_template()}. Allows for more generic file location + * Used to quickly retrieve the path of a template without including the file + * extension. It will also check the parent theme, if the file exists, with + * the use of {@link locate_template()}. Allows for more generic template location * without the use of the other get_*_template() functions. * - * Can be used with include() or require() to retrieve path. - * - * if( '' != get_query_template( '404' ) ) - * include( get_query_template( '404' ) ); - * - * or the same can be accomplished with - * - * if( '' != get_404_template() ) - * include( get_404_template() ); - * - * * @since 1.5.0 * * @param string $type Filename without extension. + * @param array $templates An optional list of template candidates * @return string Full path to file. */ -function get_query_template($type) { +function get_query_template( $type, $templates = array() ) { $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); - return apply_filters("{$type}_template", locate_template(array("{$type}.php"))); + + if ( empty( $templates ) ) + $templates = array("{$type}.php"); + + $templates = apply_filters( "{$type}_template_hierarchy", $templates ); + + return apply_filters( "{$type}_template", locate_template( $templates ) ); } /** @@ -768,8 +764,7 @@ function get_author_template() { $templates[] = "author-{$author_id}.php"; $templates[] = 'author.php'; - $template = locate_template( $templates ); - return apply_filters( 'author_template', $template ); + return get_query_template( 'author', $templates ); } /** @@ -790,14 +785,13 @@ function get_category_template() { $templates = array(); - if ( !is_wp_error($category) ) + if ( !is_wp_error( $category ) ) $templates[] = "category-{$category->slug}.php"; $templates[] = "category-$cat_ID.php"; $templates[] = "category.php"; - $template = locate_template($templates); - return apply_filters('category_template', $template); + return get_query_template( 'category', $templates ); } /** @@ -824,8 +818,7 @@ function get_tag_template() { $templates[] = "tag-$tag_id.php"; $templates[] = "tag.php"; - $template = locate_template($templates); - return apply_filters('tag_template', $template); + return get_query_template( 'tag', $templates ); } /** @@ -857,8 +850,7 @@ function get_taxonomy_template() { $templates[] = "taxonomy.php"; - $template = locate_template($templates); - return apply_filters('taxonomy_template', $template); + return get_query_template( 'taxonomy', $templates ); } /** @@ -885,8 +877,9 @@ function get_date_template() { * @return string */ function get_home_template() { - $template = locate_template(array('home.php', 'index.php')); - return apply_filters('home_template', $template); + $templates = array( 'home.php', 'index.php' ); + + return get_query_template( 'home', $templates ); } /** @@ -900,7 +893,9 @@ function get_home_template() { * @return string */ function get_front_page_template() { - return apply_filters( 'front_page_template', locate_template( array('front-page.php') ) ); + $templates = array('front-page.php'); + + return get_query_template( 'front_page', $templates ); } /** @@ -939,7 +934,7 @@ function get_page_template() { $templates[] = "page-$id.php"; $templates[] = "page.php"; - return apply_filters('page_template', locate_template($templates)); + return get_query_template( 'page', $templates ); } /** @@ -976,7 +971,8 @@ function get_single_template() { $object = $wp_query->get_queried_object(); $templates = array('single-' . $object->post_type . '.php', 'single.php'); - return apply_filters('single_template', locate_template($templates)); + + return get_query_template( 'single', $templates ); } /** @@ -1019,13 +1015,13 @@ function get_attachment_template() { * @return string */ function get_comments_popup_template() { - $template = locate_template(array("comments-popup.php")); + $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) ); // Backward compat code will be removed in a future release if ('' == $template) $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php'; - return apply_filters('comments_popup_template', $template); + return $template; } /**