[wp-trac] [WordPress Trac] #40038: Padding load_template's require with a do_action on each end

WordPress Trac noreply at wordpress.org
Sun Mar 5 17:08:54 UTC 2017


#40038: Padding load_template's require with a do_action on each end
-------------------------+-----------------------------
 Reporter:  qwertyzw     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  4.7.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Pad the requires in load_template in wp-includes\template.php with a
 do_action on each end so it looks like this:

 {{{#!php
 <?php
 function load_template( $_template_file, $require_once = true ) {
         global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite,
 $wpdb, $wp_version, $wp, $id, $comment, $user_ID;

         if ( is_array( $wp_query->query_vars ) ) {
                 extract( $wp_query->query_vars, EXTR_SKIP );
         }

         if ( isset( $s ) ) {
                 $s = esc_attr( $s );
         }

         do_action('load_template_before', $_template_file); // new line
         if ( $require_once ) {
                 require_once( $_template_file );
         } else {
                 require( $_template_file );
         }
         do_action('load_template_after', $_template_file); // new line
 }
 }}}

 this will allow plugin and theme developers to pad each template with
 html.

 At the very least for debugging purposes you'd be able to do something
 like this

 {{{#!php
 <?php
 add_action('load_template_before', 'debug_pad_before');
 add_action('load_template_after', 'debug_pad_after');

 function debug_pad_before($template){
     echo('<!-- template begin ' . $template . ' -->');
 }

 function debug_pad_after($template){
     echo('<!-- template end ' . $template . ' -->');
 }
 }}}

 I'm specifically targeting this function because it's used not only by
 wordpress but by buddypress as well, and I anticipate other extensions to
 fall back to this same function. Buddypress uses its own
 bp_locate_template but uses wordpress' load_template to load them.

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


More information about the wp-trac mailing list