[wp-trac] [WordPress Trac] #21062: Add a 'template_file' hook to load_template()
WordPress Trac
wp-trac at lists.automattic.com
Sun Jun 24 21:04:51 UTC 2012
#21062: Add a 'template_file' hook to load_template()
--------------------------+------------------------------------
Reporter: mikeschinkel | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Template | Version: 3.4
Severity: normal | Keywords: has-patch dev-feedback
--------------------------+------------------------------------
Please consider adding a `'template_file'` hook in `load_template()` to
enable the capture of the template filename. I have built a panel for the
Debug Bar to be able to show template files loaded but I need this
`'template_file'` hook to capture the template file names. This would be
super useful for developers who are building sites with the complex
template loading logic found in various theme frameworks et. al.
With the hook added the code for `load_template()` might look like this:
{{{
function load_template( $_template_file, $require_once = true ) {
global $posts, $post, $wp_did_header, $wp_did_template_redirect,
$wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
if ( is_array( $wp_query->query_vars ) )
extract( $wp_query->query_vars, EXTR_SKIP );
$_template_file = apply_filters( 'template_file', $_template_file,
$require_once );
if ( $require_once )
require_once( $_template_file );
else
require( $_template_file );
}
}}}
Here's a screenshot showing the Theme Template Files panel I implemented
so you can see the use-case. This plugin requires the hook I'm proposing
in order to work and I have attached the plugin for other's review.
{{{
#!html
<img src="http://screenshots.newclarity.net/skitched-20120624-165532.png"
/>
}}}
This hook could also allow the loading of the template file from other
directories such as a shared directory on a server, as appropriate, but
that's not the reason I found the need today.
The source for `load_template()` is found in `/wp-includes/template.php`.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21062>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list