Opened 8 years ago
Last modified 8 years ago
#40038 new enhancement
Padding load_template's require with a do_action on each end
Reported by: | qwertyzw | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 1.5 |
Component: | Themes | Keywords: | has-patch needs-refresh |
Focuses: | template | Cc: |
Description
Pad the requires in load_template in wp-includes\template.php with a do_action on each end so it looks like this:
<?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 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.
Attachments (2)
Change History (5)
#2
follow-up:
↓ 3
@
8 years ago
- Component changed from General to Themes
- Focuses template added
- Keywords has-patch needs-refresh added
- Milestone changed from Awaiting Review to Future Release
- Version changed from 4.7.2 to 1.5
Thanks for the patch, @qwertyzw, and thanks for letting us know the reason you'd like these actions added.
It looks like your diff is in reverse. Do you want to try again? (You can upload a diff with the same file name.)
#3
in reply to:
↑ 2
@
8 years ago
Replying to johnbillion:
Thanks for the patch, @qwertyzw, and thanks for letting us know the reason you'd like these actions added.
It looks like your diff is in reverse. Do you want to try again? (You can upload a diff with the same file name.)
Ahh, I was following the instructions at https://make.wordpress.org/core/handbook/contribute/git/
I think they need a review
Added a .diff