<!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>[13252] trunk/wp-includes/template-loader.php: Add template_include filter,
to modify the template path before it is included.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13252">13252</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-02-20 12:58:25 +0000 (Sat, 20 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add template_include filter, to modify the template path before it is included. Fixes <a href="http://trac.wordpress.org/ticket/11242">#11242</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludestemplateloaderphp">trunk/wp-includes/template-loader.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludestemplateloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/template-loader.php (13251 => 13252)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/template-loader.php        2010-02-20 12:50:09 UTC (rev 13251)
+++ trunk/wp-includes/template-loader.php        2010-02-20 12:58:25 UTC (rev 13252)
</span><span class="lines">@@ -3,76 +3,44 @@
</span><span class="cx"> * Loads the correct template based on the visitor's url
</span><span class="cx"> * @package WordPress
</span><span class="cx"> */
</span><del>-if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) {
</del><ins>+if ( defined('WP_USE_THEMES') && WP_USE_THEMES )
</ins><span class="cx">         do_action('template_redirect');
</span><del>-        if ( is_robots() ) {
-                do_action('do_robots');
-                return;
-        } else if ( is_feed() ) {
-                do_feed();
-                return;
-        } else if ( is_trackback() ) {
-                include(ABSPATH . 'wp-trackback.php');
-                return;
-        } else if ( is_404() && $template = get_404_template() ) {
-                include($template);
-                return;
-        } else if ( is_search() && $template = get_search_template() ) {
-                include($template);
-                return;
-        } else if ( is_tax() && $template = get_taxonomy_template()) {
-                include($template);
-                return;
-        } else if ( is_home() && $template = get_home_template() ) {
-                include($template);
-                return;
-        } else if ( is_attachment() && $template = get_attachment_template() ) {
</del><ins>+
+// Process feeds and trackbacks even if not using themes.
+if ( is_robots() ) :
+        do_action('do_robots');
+        return;
+elseif ( is_feed() ) :
+        do_feed();
+        return;
+elseif ( is_trackback() ) :
+        include( ABSPATH . 'wp-trackback.php' );        
+        return;
+endif;
+
+if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) :
+        $template = false;
+        if ( is_404() && $template = get_404_template() ) :
+        elseif ( is_search() && $template = get_search_template() ) :
+        elseif ( is_tax() && $template = get_taxonomy_template() ) :
+        elseif ( is_home() && $template = get_home_template() ) :
+        elseif ( is_attachment() && $template = get_attachment_template() ) :
</ins><span class="cx">                 remove_filter('the_content', 'prepend_attachment');
</span><del>-                include($template);
-                return;
-        } else if ( is_single() && $template = get_single_template() ) {
-                include($template);
-                return;
-        } else if ( is_page() && $template = get_page_template() ) {
-                include($template);
-                return;
-        } else if ( is_category() && $template = get_category_template()) {
-                include($template);
-                return;
-        } else if ( is_tag() && $template = get_tag_template()) {
-                include($template);
-                return;
-        } else if ( is_author() && $template = get_author_template() ) {
-                include($template);
-                return;
-        } else if ( is_date() && $template = get_date_template() ) {
-                include($template);
-                return;
-        } else if ( is_archive() && $template = get_archive_template() ) {
-                include($template);
-                return;
-        } else if ( is_comments_popup() && $template = get_comments_popup_template() ) {
-                include($template);
-                return;
-        } else if ( is_paged() && $template = get_paged_template() ) {
-                include($template);
-                return;
-        } else if ( file_exists(TEMPLATEPATH . "/index.php") ) {
-                include(TEMPLATEPATH . "/index.php");
-                return;
-        }
-} else {
-        // Process feeds and trackbacks even if not using themes.
-        if ( is_robots() ) {
-                do_action('do_robots');
-                return;
-        } else if ( is_feed() ) {
-                do_feed();
-                return;
-        } else if ( is_trackback() ) {
-                include(ABSPATH . 'wp-trackback.php');
-                return;
-        }
-}
</del><ins>+        elseif ( is_single() && $template = get_single_template() ) :
+        elseif ( is_page() && $template = get_page_template() ) :
+        elseif ( is_category() && $template = get_category_template() ) :
+        elseif ( is_tag() && $template = get_tag_template() ) :
+        elseif ( is_author() && $template = get_author_template() ) :
+        elseif ( is_date() && $template = get_date_template() ) :
+        elseif ( is_archive() && $template = get_archive_template() ) :
+        elseif ( is_comments_popup() && $template = get_comments_popup_template() ) :
+        elseif ( is_paged() && $template = get_paged_template() ) :
+        elseif ( file_exists( TEMPLATEPATH . '/index.php' ) ) :
+                $template = TEMPLATEPATH . '/index.php';
+        endif;
+        if ( $template = apply_filters( 'template_include', $template ) )
+                include( $template );
+        return;
+endif;
</ins><span class="cx">
</span><span class="cx"> ?>
</span><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>