[wp-trac] [WordPress Trac] #42688: Option to make get_template_part return instead of require

WordPress Trac noreply at wordpress.org
Mon Nov 27 01:51:23 UTC 2017


#42688: Option to make get_template_part return instead of require
-----------------------------+------------------------------
 Reporter:  mclaurent        |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Themes           |     Version:  4.9
 Severity:  normal           |  Resolution:
 Keywords:  2nd-opinion      |     Focuses:  template
-----------------------------+------------------------------
Changes (by dd32):

 * keywords:   => 2nd-opinion
 * type:  enhancement => feature request


Comment:

 Replying to [ticket:42688 mclaurent]:
 > {{{
 > #!php
 > <?php
 > function get_product_template($atts) {
 >
 >     ob_start();
 >
 >     get_template_part( 'product', $atts['type'], false );
 >
 >     $ret = ob_get_contents();
 >     ob_end_clean();
 >     return $ret;
 > }
 > add_shortcode('products', 'get_product_template');
 > }}}

 That can be shortened to just:

 {{{
 #!php
 <?php
 function get_product_template($atts) {
     ob_start();

     get_template_part( 'product', $atts['type'] );

     return ob_get_clean();
 }
 add_shortcode( 'products', 'get_product_template' );
 }}}

 I don't see this as being too complex for a plugin to handle itself, and
 is exactly what would happen under the hood in core if we were to add the
 functionality. It's not heavy-handed at all.

 Overall, it seems that the extra two lines of code here is acceptable,
 given most plugins/themes should hopefully have a lot more sanitisation
 placed upon the data being passed into the template anyway.

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


More information about the wp-trac mailing list