[wp-trac] [WordPress Trac] #54541: Add actions to template loading to assist with collecting debug info

WordPress Trac noreply at wordpress.org
Wed Jul 20 22:29:58 UTC 2022


#54541: Add actions to template loading to assist with collecting debug info
-------------------------------------------------+-------------------------
 Reporter:  rmccue                               |       Owner:
                                                 |  johnbillion
     Type:  enhancement                          |      Status:  reopened
 Priority:  normal                               |   Milestone:  6.1
Component:  Themes                               |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-unit-tests needs-    |     Focuses:
  dev-note commit                                |  performance
-------------------------------------------------+-------------------------
Changes (by johnjamesjacoby):

 * status:  closed => reopened
 * resolution:  fixed =>


Comment:

 If I understand the intentions of this ticket and its hooks correctly,
 `locate_template()` may be the wrong function location for these hooks, or
 these hooks would perhaps benefit from a slightly different naming
 convention.

 ----

 Is it possible that `load_template()` is where these exact hooks belong
 (with the `$template_names` param removed)? Obviously, that is the
 function responsible for requiring the located file with the intended
 variables available to it, and the measurable code execution for Query
 Monitor is the extraction of the `query_vars` and the rendering/inclusion
 of the template file.

 In addition, `load_template()` is used by many of the most popular
 WordPress plugins – not `locate_template()` – which means their template
 parts will never see these hooks fire and unable to benefit from any
 imaginary fragment caching implementation that may-or-may-not come in the
 future because of these hooks.

 === Scopecreep

 The Feeds feature in WordPress also uses `load_template()`  via the
 `do_feed()` function (through `do_action( "do_feed_{$feed}" )`) which kind
 of seems to me like it should have its own special case inside of
 `locate_template()` the way that `theme-compat` does so that Feeds can use
 `locate_template()` while also enabling Query Monitor to use the same
 hooks.

 == Plugins

 Mostly, these plugins use `load_template()` to get around the fact that
 `locate_template()` is strictly locked down to the parent/child theme
 hierarchy, and they write their own "locators" with extra locations to add
 to the core hierarchy under certain controlled conditions.

 * bbPress & BuddyPress for theme compatibility
 * EDD for loading template parts
 * WooCommerce for loading template parts
 * WPForms for loading template parts
 * Events Calendar for loading template parts
 * Jetpack for loading `inline-help-template.php`
 * A bunch more... 😅

 Those (any) custom locator will not benefit from the actions being added
 here.

 In total, there are around 10,085 usages in the Plugins repository
 (according to wpdirectory.net) that will not know what is happening before
 or after their own calls to `load_template()` because they are not using
 `locate_template()`.

 Asking respectfully for your friendly additional thoughts & feedbacks 💫🤝

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


More information about the wp-trac mailing list