[wp-trac] [WordPress Trac] #13239: Filter locate_template template_names variable

WordPress Trac noreply at wordpress.org
Sun Mar 9 06:16:28 UTC 2014


#13239: Filter locate_template template_names variable
--------------------------+-----------------------
 Reporter:  chrisbliss18  |       Owner:
     Type:  enhancement   |      Status:  reopened
 Priority:  normal        |   Milestone:  3.9
Component:  Themes        |     Version:  3.0
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+-----------------------

Comment (by casben79):

 Would it be possible to add a filter to the full path right before its
 passed back?

 Here is the use case I have.

 I have a plugin which supports templating of small parts of output
 (http://wordpress.org/plugins/wp-slick-slider/), it currently has some
 rather messy code like below:


 {{{
 if( file_exists( $wpss_templatepath . '/' . $slider . '_full-width-
 image.php' ) ){
     $include = $wpss_templatepath . '/' . $slider . '_full-width-
 image.php';
 } elseif( file_exists( $wpss_templatepath . '/full-width-image.php' ) ) {
     $include = $wpss_templatepath . '/full-width-image.php';
 } else {
     $include = $wpss_default_path . '/full-width-image.php';
 }
 }}}

 if I clean that up to something like this:


 {{{
 $templates = array(
     "wpss/{$slider}_full-width-image.php",
     "wpss/full-width-image.php",
 );
 $include = locate_template( $templates );

 if( $include === '' ){
     $include = $wpss_default_path . '/full-width-image.php';
 }
 }}}

 and there is a filter on the full path in `locate_template()` like so:


 {{{
 return apply_filters( 'after_locate_template', $located, $template_names
 );
 }}}

 This would allow my plugin (and any other plugin whose author uses
 locate_template() to template the output) to be modified by another plugin
 of mine (http://wordpress.org/plugins/wp-template-overrides/) which is
 designed to tweak template files by creating a file in a completely
 different path (/wp-content/theme-overrides/) and hooking into
 `template_include`

 Using this combination, any user would be able override any templating
 that uses `locate_template()` without modifying the theme (EG: premium
 themes)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/13239#comment:70>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list