[wp-trac] [WordPress Trac] #58866: Avoid consts inside `locate_template` as it gives incorrect template path after switch_theme

WordPress Trac noreply at wordpress.org
Wed Jul 26 15:28:03 UTC 2023


#58866: Avoid consts inside `locate_template` as it gives incorrect template path
after switch_theme
-------------------------------------------------+-------------------------
 Reporter:  thekt12                              |       Owner:  thekt12
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  6.4
Component:  Themes                               |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  good-first-bug has-patch reporter-   |     Focuses:  template
  feedback                                       |
-------------------------------------------------+-------------------------

Comment (by thekt12):

 @joemcgill Yes, I can confirm this is a duplicate of #18298.
 @mukesh27 I agree that switching to function will cause performance
 regression.


 w.r.t Real site, unless the site is build to performing heavy business
 logic after switching theme in background, this would hardly cause any
 major issue as most of the issues dies off once the page is reloaded; It
 would be just one entry for each theme switch.

 However, if we stick to the constants the way it is right now we will lose
 the ability to write test cases for some functions consuming it. i.e
 `locate_template` or `is_child_theme`

 I personally feel both functions and constants are not the best approach,
 better would be to use global variables for both stylesheet and template.

 This way we can call `wp_templating_constants()` functions again after
 `switch_theme` and update the variables. And also we address the looping
 issue and most of the performance regression caused by use of functions.

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


More information about the wp-trac mailing list