Index: wp-includes/theme.php
===================================================================
--- wp-includes/theme.php	(revision 15432)
+++ wp-includes/theme.php	(working copy)
@@ -687,32 +687,28 @@
 }
 
 /**
- * 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.
- * <code>
- * if( '' != get_query_template( '404' ) )
- *     include( get_query_template( '404' ) );
- * </code>
- * or the same can be accomplished with
- * <code>
- * if( '' != get_404_template() )
- *     include( get_404_template() );
- * </code>
- *
  * @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_candidates", $templates );
+
+	return apply_filters( "{$type}_template", locate_template( $templates ) );
 }
 
 /**
@@ -768,8 +764,7 @@
 		$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 @@
 
 	$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 @@
 		$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 @@
 
 	$templates[] = "taxonomy.php";
 
-	$template = locate_template($templates);
-	return apply_filters('taxonomy_template', $template);
+	return get_query_template( 'taxonomy', $templates );
 }
 
 /**
@@ -885,8 +877,9 @@
  * @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 @@
  * @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 @@
 		$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 @@
 
 	$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 @@
  * @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 = WPINC . '/theme-compat/comments-popup.php';
 
-	return apply_filters('comments_popup_template', $template);
+	return $template;
 }
 
 /**
