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

WordPress Trac wp-trac at lists.automattic.com
Mon May 3 21:43:06 UTC 2010


#13239: Filter locate_template template_names variable
--------------------------+-------------------------------------------------
 Reporter:  chrisbliss18  |       Owner:                         
     Type:  enhancement   |      Status:  new                    
 Priority:  normal        |   Milestone:  Unassigned             
Component:  Themes        |     Version:  3.0                    
 Severity:  normal        |    Keywords:  has-patch commit tested
--------------------------+-------------------------------------------------
 I recently encountered a situation where it would be very helpful to
 supply alternate template file locations; however, this cannot be
 accomplished as the locate_template function is being used and that
 function's arguments are not filterable. So, I created a patch that adds
 the filter.

 This patch adds two filters: locate_template and locate_template-
 TEMPLATENAME. This allows for both general and specific filtering.

 The following example shows how this could be used to modify the location
 of a BuddyPress template file.

 {{{
 function filter_member_header_template( $template ) {
     return dirname( __FILE__ ) . '/buddypress/members/single/member-
 header.php';
 }
 add_filter( 'locate_template-members/single/member-header.php',
 'filter_member_header_template' );
 }}}

 While the value of this example is debatable as BuddyPress could be
 updated to support alternate template locations, the value of the patch
 itself is high. This opens up a new ability for plugins to modify template
 file locations, giving plugins a hook into the content rendering process
 without requiring themes to be modified.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/13239>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list