[wp-trac] [WordPress Trac] #57928: Prevent loading wp-content/themes/functions.php when 'stylesheet' option is empty

WordPress Trac noreply at wordpress.org
Thu Jun 1 02:47:13 UTC 2023


#57928: Prevent loading wp-content/themes/functions.php when 'stylesheet' option is
empty
------------------------------------+------------------------------
 Reporter:  danielbachhuber         |       Owner:  danielbachhuber
     Type:  enhancement             |      Status:  assigned
 Priority:  normal                  |   Milestone:  6.3
Component:  Bootstrap/Load          |     Version:
 Severity:  normal                  |  Resolution:
 Keywords:  dev-feedback has-patch  |     Focuses:
------------------------------------+------------------------------

Comment (by costdev):

 Regarding available usage:

 - Here's [https://github.com/search?q=wp-
 content%2Fthemes%2Ffunctions.php&type=code a GitHub Code Search result]
 for `wp-content/themes/functions.php` that might provide some insight into
 its usage.
 - Here's [https://wpdirectory.net/search/01H1T8ZBBG5DS541EFX23R5NEA 7
 plugin results at WP Directory] that hook `wp_using_themes`.
   - Sensei LMS, Print My Blog, and Leyka explicitly return `false`.
   - Print My Blog filters `wp_using_themes` inside a `template_redirect`
 action callback. Immediately after hooking `template_redirect`, it filters
 `template_directory`. This may not be pertinent, but as an earlier comment
 mentioned the `template_directory` filter when used alongside an empty
 `template` value, I thought I'd mention this one so that it could be
 considered/ruled out as a risk factor.

 -----

 From the comments on this ticket, there's no doubt that this has caused
 real-world issues for several folks when using `--skip-themes`. It's an
 edge case, therefore not widespread, but still a valid issue. At the
 moment, we have three approaches for a Core patch: two with known backward
 compatibility breaks, and one that might be the least/most risky option.
 As yet, I don't have a strong opinion on which approach is preferred/most
 viable.

 However, given that `wp_get_active_and_valid_themes()` itself expects that
 filtering `wp_using_themes` with `false` should skip loading themes
 [https://github.com/WordPress/wordpress-develop/blob/6.2/src/wp-
 includes/load.php#L957-L960 Ref] and then returns an empty array,
 [https://github.com/WordPress/wordpress-develop/pull/4409 PR 4409] looks
 to be consistent with Core.

 @danielbachhuber Regarding [https://github.com/WordPress/wordpress-
 develop/pull/4409 PR 4409], you previously said:
 > However, it would be a backwards compat break for any site with
 `add_filter( 'wp_using_themes', '__return_false' );` and a valid
 `template` value, because the theme's `functions.php` would no longer be
 loaded.

 I'm wondering if this really constitutes a BC break by changing behaviour
 that some people want, or whether it's actually just fixing undocumented,
 buggy behaviour that no one wants. At the moment, I suspect it's the
 latter.

 Can you think of a scenario/use case for someone expecting `wp-
 content/themes/functions.php` to be loaded here, despite passing
 `__return_false` to `wp_using_themes`? Aside from the fact it currently
 does load it, I can't quite think of an example where someone would say
 "Don't use themes, but go ahead and load this file in the themes
 directory".

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


More information about the wp-trac mailing list