[wp-trac] [WordPress Trac] #28094: Add action hook after getting template part

WordPress Trac noreply at wordpress.org
Thu May 1 15:43:48 UTC 2014


#28094: Add action hook after getting template part
-----------------------------+-----------------------------
 Reporter:  andrezrv         |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Themes           |    Version:  3.9
 Severity:  normal           |   Keywords:
  Focuses:  template         |
-----------------------------+-----------------------------
 I think it should be nice to have the possibility to execute actions after
 getting a template part, not only before doing it, as it is now. I find
 this can be particularly useful to deal with output buffering, allowing to
 do things like this:


 {{{
 <?php
 add_action( 'get_template_part_content', 'catch_template_part_output' );
 /**
  * Start output buffering for template part.
  */
 function catch_template_part_output( $slug, $name = null ) {
         if ( '' == $name ) {
                 ob_start();
         }
 }

 add_action( 'after_get_template_part_content',
 'release_template_part_output' );
 /**
  * End output buffering for template part and print modified output.
  */
 function release_template_part_output( $slug, $name = null ) {
         if ( '' == $name ) {
                 $output = ob_get_contents();
                 $output = '[Something before the original output ...]' .
 $output;
                 $output .= '[Something after the original output ...]';
                 ob_clean();
                 echo $output;
         }
 }
 }}}

 I'm thinking this particular method could give an extra option to theme
 developers who need to modify a very simple piece of output without having
 to create a new template or new functions to be embedded into an existing
 template. I know maybe some people won't consider this to be a recommended
 practice (I'm actually a little divided here), but you'd still have the
 possibility to trigger any other functionality you want on such hook.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28094>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list