Make WordPress Core

Opened 4 years ago

Last modified 14 months ago

#15957 reviewing enhancement

add two new actions to track template loading

Reported by: willnorris Owned by: koopersmith
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: template Cc:


I would like to add two new actions "pre_load_template" and "post_load_template" inside the load_template() method. The purpose of this is primarily for debugging and development purposes. For example, I'd like to use these actions to add debug comments in a theme's output along the lines of:

<!-- begin ../themes/twentyten/loop.php -->
<!-- end ../themes/twentyten/loop.php -->

This makes it much easier to identify which theme file is responsible for which part of the final page, particularly in the case where some files are being pulled from a parent theme and some are from the child theme.

Attachments (1)

theme.diff (542 bytes) - added by willnorris 4 years ago.

Download all attachments as: .zip

Change History (8)

@willnorris4 years ago

comment:1 @scribu4 years ago

Related: #13239, #12877

I think a single filter would suffice. You can use the 'shutdown' action instead of 'post_load_template'.

comment:2 @willnorris4 years ago

  • Component changed from Themes to Template

I'm actually using this with Daryl's modular template idea (#12877) so it's definitely related. As for the 'shutdown' action, unless I'm mistaken, that's only called when PHP shuts down. The idea of 'post_load_template' is to be called at the end of each template loading. Since a dozen or more template files can sometimes be involved in constructing a page, this allows you to clearly mark the beginning and end of each template.

comment:3 @markjaquith4 years ago

  • Owner set to koopersmith
  • Status changed from new to reviewing

Asking for Daryl to weigh in.

comment:4 @koopersmith4 years ago

  • Milestone changed from Awaiting Review to Future Release

While the ability to be able to insert content before and after a template is sensible in this context, I'd like to wait before introducing new actions.

I think that at this point, the best way to improve the themes API is to add carefully designed, comprehensive concepts instead of bolting on more functions and filters. I know that this makes certain cases more difficult now, but it will benefit us when it comes to maintaining backwards compatibility later.

In this case, I think that if the concepts are executed properly, these actions won't be necessary.

comment:5 @willnorris4 years ago

Daryl: I'm all for a comprehensive update to the Themes API rather than bandaids like this. Is there a good place to track this work? A ticket where most of this is happening?

comment:6 @ericlewis3 years ago

Related: #13239

Version 0, edited 3 years ago by ericlewis (next)

comment:7 @nacin14 months ago

  • Component changed from Template to Themes
  • Focuses template added
Note: See TracTickets for help on using tickets.