[wp-trac] [WordPress Trac] #15061: Allow either array or string to be passed to locate_template

WordPress Trac wp-trac at lists.automattic.com
Thu Oct 7 17:38:10 UTC 2010


#15061: Allow either array or string to be passed to locate_template
--------------------------+-------------------------------------------------
 Reporter:  chrisbliss18  |       Owner:                 
     Type:  enhancement   |      Status:  new            
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Template      |     Version:                 
 Severity:  normal        |    Keywords:  has-patch      
--------------------------+-------------------------------------------------
 Currently, template file names have to be passed as an array to the
 locate_template function:

 {{{
 locate_template(array('category-new.php', 'category.php'));
 }}}

 Passing in multiple template file names is a very powerful feature;
 however, outside of core, most code simply needs to locate a single
 template file name. As can be seen from this variety of locate_template
 calls made in BuddyPress:

 {{{
 locate_template( array( 'members/single/activity.php' ), true );
 locate_template( array( 'members/single/messages.php' ), true );
 locate_template( array( 'members/single/profile/edit.php' ), true );
 locate_template( array( 'members/members-loop.php' ), true );
 locate_template( array( 'activity/activity-loop.php' ), true );
 locate_template( array( 'groups/single/forum.php' ), true );
 locate_template( array( 'sidebar.php' ), true );
 locate_template( array( 'groups/single/group-header.php' ), true );
 }}}

 Note that this is just a very small sampling. In total, locate_template is
 used 89 times in BuddyPress, and not once is more than a single file
 passed to locate_template.

 My attached patch makes working with locate_template much easier for
 general usage by allowing either a string or array for the $template_names
 argument. A string argument will be changed into an array.

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


More information about the wp-trac mailing list