[wp-trac] [WordPress Trac] #58758: Cached result for wp_theme_has_theme_json() is not invalided when theme is switched dynamically
WordPress Trac
noreply at wordpress.org
Fri Jul 7 17:42:43 UTC 2023
#58758: Cached result for wp_theme_has_theme_json() is not invalided when theme is
switched dynamically
--------------------------+--------------------------
Reporter: westonruter | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.2.3
Component: Themes | Version: 6.2
Severity: normal | Resolution:
Keywords: has-patch | Focuses: performance
--------------------------+--------------------------
Description changed by westonruter:
Old description:
> In #56975 the return value of `wp_theme_has_theme_json()` was cached
> unless the `WP_RUN_CORE_TESTS` or `WP_DEBUG` constants are true. (In
> #57487 the `WP_DEBUG` constant was replaced with a
> `wp_get_development_mode() !== 'theme'` check.) This workaround is needed
> to:
>
> > Ignore cache when automated test suites are running. Why? To ensure the
> static cache is reset between each test.
>
> This is because core unit tests often switch themes, resulting in a stale
> cache. However, sites in the wild also can also dynamically switch
> themes, and plugins may switch themes during their own unit tests. It
> seems this check is not ideal and is masking a more fundamental problem:
> the cached value is not invalidated when the theme is dynamically
> switched.
New description:
In #56975 the return value of `wp_theme_has_theme_json()` was cached
unless the `WP_RUN_CORE_TESTS` or `WP_DEBUG` constants are true. (In
#57487 the `WP_DEBUG` constant was replaced with a
`wp_get_development_mode() !== 'theme'` check.) This workaround is needed
to:
> Ignore cache when automated test suites are running. Why? To ensure the
static cache is reset between each test.
This is because core unit tests often switch themes, resulting in a stale
cache. However, sites in the wild also can also dynamically switch themes,
and plugins may switch themes during their own unit tests. It seems this
check is not ideal and is masking a more fundamental problem: the cached
value is not invalidated when the theme is dynamically switched.
A simple fix is to invalidate the cache whenever
`get_stylesheet_directory()` or `get_template_directory()` change.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58758#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list