[wp-trac] [WordPress Trac] #18561: Better Way to Insert Things Below Individual Posts

WordPress Trac wp-trac at lists.automattic.com
Thu Sep 1 19:11:57 UTC 2011


#18561: Better Way to Insert Things Below Individual Posts
-------------------------+------------------------------
 Reporter:  jane         |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:  3.2.1
 Severity:  minor        |  Resolution:
 Keywords:               |
-------------------------+------------------------------

Comment (by johnjamesjacoby):

 Replying to [comment:56 Otto42]:
 > Replying to [comment:54 johnjamesjacoby]:
 > > That said, I'm all for get_template_part() getting more muscle. It's
 because of a lack of filters and actions that bbPress 2.0 has its own
 wrapper for it: http://bbpress.trac.wordpress.org/browser/branches/plugin
 /bbp-includes/bbp-core-compatibility.php#L82
 > >
 > > Otto's patch is a good start but get_template_part() could/should be
 much more powerful. Example: bbPress 2.0 uses template parts to power its
 shortcodes so that a theme *can* dictate the appearance if it elects to,
 but it doesn't have to. Template parts are loaded into on output buffer,
 and presented wherever you put them. Easy.
 >
 > BTW, I was looking at this the other day, and for your specific use case
 in bbPress, I think a filter down in locate_template makes the most sense.
 Putting this in there would work:
 >
 > {{{
 > $located = apply_filters( 'locate_template', $located, $template_names
 );
 > }}}
 >
 > It allows a plugin to either override any existing template, or find/add
 a different template from a different directory, if needed. This would
 give the functionality you were talking about back in Chicago without the
 wrapper.

 I will do you one better. You get the idea:

 {{{
 function locate_template($template_names, $load = false, $require_once =
 true ) {

         // Setup names and paths
         $template_paths = array( TEMPLATEPATH, STYLESHEETPATH );
         $template_names = apply_filters( 'locate_template_names',
 $template_names );
         $template_paths = apply_filters( 'locate_template_paths',
 $template_paths );

         // Remove empties
         $template_names = array_filter( $template_names );
         $template_paths = array_filter( $template_paths );

         // Reverse paths so no reordering is needed by themes or plugins
         $template_paths = array_reverse( $template_paths );

         // Allow overloading of locate_template
         $located        = apply_filters( 'pre_locate_template', '',
 $template_names, $template_paths );

         // Skip the check if a filter overloaded
         if ( empty( $located ) ) {

                 // Loop through template names
                 foreach ( (array) $template_names as $template_name ) {

                         // Loop through paths
                         foreach ( (array) $template_paths as
 $template_path ) {

                                 // File exists
                                 if ( file_exists( $template_path . '/' .
 $template_name ) ) {
                                         $located = $template_path . '/' .
 $template_name;
                                         break;
                                 }
                         }
                 }
         }

         // Only load the template if one is found
         if ( $load && '' !== $located )
                 load_template( $located, $require_once );

         return $located;
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18561#comment:58>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list