<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[15611] trunk/wp-includes/theme.php:
  Apply filters consistently in get_*_template() functions.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15611">15611</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-09-12 18:46:18 +0000 (Sun, 12 Sep 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Apply filters consistently in get_*_template() functions. Fixes <a href="http://trac.wordpress.org/ticket/14310">#14310</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (15610 => 15611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2010-09-12 16:21:34 UTC (rev 15610)
+++ trunk/wp-includes/theme.php        2010-09-12 18:46:18 UTC (rev 15611)
</span><span class="lines">@@ -687,32 +687,28 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Retrieve path to file without the use of extension.
</del><ins>+ * Retrieve path to a template
</ins><span class="cx">  *
</span><del>- * 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
</del><ins>+ * 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
</ins><span class="cx">  * without the use of the other get_*_template() functions.
</span><span class="cx">  *
</span><del>- * Can be used with include() or require() to retrieve path.
- * &lt;code&gt;
- * if( '' != get_query_template( '404' ) )
- *     include( get_query_template( '404' ) );
- * &lt;/code&gt;
- * or the same can be accomplished with
- * &lt;code&gt;
- * if( '' != get_404_template() )
- *     include( get_404_template() );
- * &lt;/code&gt;
- *
</del><span class="cx">  * @since 1.5.0
</span><span class="cx">  *
</span><span class="cx">  * @param string $type Filename without extension.
</span><ins>+ * @param array $templates An optional list of template candidates
</ins><span class="cx">  * @return string Full path to file.
</span><span class="cx">  */
</span><del>-function get_query_template($type) {
</del><ins>+function get_query_template( $type, $templates = array() ) {
</ins><span class="cx">         $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
</span><del>-        return apply_filters(&quot;{$type}_template&quot;, locate_template(array(&quot;{$type}.php&quot;)));
</del><ins>+
+        if ( empty( $templates ) )
+                $templates = array(&quot;{$type}.php&quot;);
+
+        $templates = apply_filters( &quot;{$type}_template_hierarchy&quot;, $templates );
+
+        return apply_filters( &quot;{$type}_template&quot;, locate_template( $templates ) );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -768,8 +764,7 @@
</span><span class="cx">                 $templates[] = &quot;author-{$author_id}.php&quot;;
</span><span class="cx">         $templates[] = 'author.php';
</span><span class="cx"> 
</span><del>-        $template = locate_template( $templates );
-        return apply_filters( 'author_template', $template );
</del><ins>+        return get_query_template( 'author', $templates );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -790,14 +785,13 @@
</span><span class="cx"> 
</span><span class="cx">         $templates = array();
</span><span class="cx"> 
</span><del>-        if ( !is_wp_error($category) )
</del><ins>+        if ( !is_wp_error( $category ) )
</ins><span class="cx">                 $templates[] = &quot;category-{$category-&gt;slug}.php&quot;;
</span><span class="cx"> 
</span><span class="cx">         $templates[] = &quot;category-$cat_ID.php&quot;;
</span><span class="cx">         $templates[] = &quot;category.php&quot;;
</span><span class="cx"> 
</span><del>-        $template = locate_template($templates);
-        return apply_filters('category_template', $template);
</del><ins>+        return get_query_template( 'category', $templates );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -824,8 +818,7 @@
</span><span class="cx">                 $templates[] = &quot;tag-$tag_id.php&quot;;
</span><span class="cx">         $templates[] = &quot;tag.php&quot;;
</span><span class="cx"> 
</span><del>-        $template = locate_template($templates);
-        return apply_filters('tag_template', $template);
</del><ins>+        return get_query_template( 'tag', $templates );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -857,8 +850,7 @@
</span><span class="cx"> 
</span><span class="cx">         $templates[] = &quot;taxonomy.php&quot;;
</span><span class="cx"> 
</span><del>-        $template = locate_template($templates);
-        return apply_filters('taxonomy_template', $template);
</del><ins>+        return get_query_template( 'taxonomy', $templates );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -885,8 +877,9 @@
</span><span class="cx">  * @return string
</span><span class="cx">  */
</span><span class="cx"> function get_home_template() {
</span><del>-        $template = locate_template(array('home.php', 'index.php'));
-        return apply_filters('home_template', $template);
</del><ins>+        $templates = array( 'home.php', 'index.php' );
+
+        return get_query_template( 'home', $templates );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -900,7 +893,9 @@
</span><span class="cx">  * @return string
</span><span class="cx">  */
</span><span class="cx"> function get_front_page_template() {
</span><del>-        return apply_filters( 'front_page_template', locate_template( array('front-page.php') ) );
</del><ins>+        $templates = array('front-page.php');
+
+        return get_query_template( 'front_page', $templates );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -939,7 +934,7 @@
</span><span class="cx">                 $templates[] = &quot;page-$id.php&quot;;
</span><span class="cx">         $templates[] = &quot;page.php&quot;;
</span><span class="cx"> 
</span><del>-        return apply_filters('page_template', locate_template($templates));
</del><ins>+        return get_query_template( 'page', $templates );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -976,7 +971,8 @@
</span><span class="cx"> 
</span><span class="cx">         $object = $wp_query-&gt;get_queried_object();
</span><span class="cx">         $templates = array('single-' . $object-&gt;post_type . '.php', 'single.php');
</span><del>-        return apply_filters('single_template', locate_template($templates));
</del><ins>+
+        return get_query_template( 'single', $templates );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -1019,13 +1015,13 @@
</span><span class="cx">  * @return string
</span><span class="cx">  */
</span><span class="cx"> function get_comments_popup_template() {
</span><del>-        $template = locate_template(array(&quot;comments-popup.php&quot;));
</del><ins>+        $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) );
</ins><span class="cx"> 
</span><span class="cx">         // Backward compat code will be removed in a future release
</span><span class="cx">         if ('' == $template)
</span><span class="cx">                 $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php';
</span><span class="cx"> 
</span><del>-        return apply_filters('comments_popup_template', $template);
</del><ins>+        return $template;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>