@@ -264,6 +264,22 @@ function ( $item ) {
264264 * @return boolean
265265 */
266266function wp_theme_has_theme_json () {
267+ /**
268+ * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
269+ * See `wp_cache_add_non_persistent_groups` in src/wp-includes/load.php and other places.
270+ *
271+ * The rationale for this is to make sure derived data from theme.json
272+ * is always fresh from the potential modifications done via hooks
273+ * that can use dynamic data (modify the stylesheet depending on some option,
274+ * settings depending on user permissions, etc.).
275+ * See some of the existing hooks to modify theme.json behaviour:
276+ * https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
277+ *
278+ * A different alternative considered was to invalidate the cache upon certain
279+ * events such as options add/update/delete, user meta, etc.
280+ * It was judged not enough, hence this approach.
281+ * See https://github.com/WordPress/gutenberg/pull/45372
282+ */
267283 $ cache_group = 'theme_json ' ;
268284 $ cache_key = 'wp_theme_has_theme_json ' ;
269285 $ theme_has_support = wp_cache_get ( $ cache_key , $ cache_group );
@@ -295,3 +311,14 @@ function wp_theme_has_theme_json() {
295311
296312 return (bool ) $ theme_has_support ;
297313}
314+
315+ /**
316+ * Private function to clean the caches under the theme_json group.
317+ *
318+ * @since 6.1.2
319+ * @access private
320+ */
321+ function _wp_clean_theme_json_caches () {
322+ wp_cache_delete ( 'wp_theme_has_theme_json ' , 'theme_json ' );
323+ WP_Theme_JSON_Resolver::clean_cached_data ();
324+ }
0 commit comments