[wp-trac] [WordPress Trac] #28689: Add a filter to the locate_template() function
WordPress Trac
noreply at wordpress.org
Mon Jun 30 11:15:36 UTC 2014
#28689: Add a filter to the locate_template() function
-------------------------+-----------------------------
Reporter: aristath | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: trunk
Severity: normal | Keywords:
Focuses: template |
-------------------------+-----------------------------
Hello everyone!
I was trying to change the location of the template files today and
realized that there's no non-hacky way to do this. Sure template
redirecting is a way but it's pretty limited and has a lot of drawbacks.
Instead, we could simply add a filter to the locate_template() function.
So instead of this:
{{{#!php
function locate_template($template_names, $load = false, $require_once =
true ) {
$located = '';
foreach ( (array) $template_names as $template_name ) {
if ( !$template_name )
continue;
if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
$located = STYLESHEETPATH . '/' . $template_name;
break;
} else if ( file_exists(TEMPLATEPATH . '/' .
$template_name) ) {
$located = TEMPLATEPATH . '/' . $template_name;
break;
}
}
if ( $load && '' != $located )
load_template( $located, $require_once );
return $located;
}
}}}
We could instead add a filter and do it like this:
{{{#!php
function locate_template($template_names, $load = false, $require_once =
true ) {
$located = '';
foreach ( (array) $template_names as $template_name ) {
if ( !$template_name )
continue;
if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
$located = STYLESHEETPATH . '/' . $template_name;
break;
} else if ( file_exists(TEMPLATEPATH . '/' .
$template_name) ) {
$located = TEMPLATEPATH . '/' . $template_name;
break;
}
}
if ( $load && '' != $located )
load_template( $located, $require_once );
return apply_filters( 'locate_template', $located );
}
}}}
That would allow us greater flexibility and would be really easy to
customize!
Are there any objections or should I just submit a patch for that?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28689>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list