99 * Gets the settings resulting of merging core, theme, and user data.
1010 *
1111 * @since 5.9.0
12+ * @since 7.2.0 Removed the per-request cache; WP_Theme_JSON_Resolver::get_merged_data() caches the merged data.
1213 *
1314 * @param array $path Path to the specific setting to retrieve. Optional.
1415 * If empty, will return all settings.
@@ -32,53 +33,13 @@ function wp_get_global_settings( $path = array(), $context = array() ) {
3233 $ path = $ new_path ;
3334 }
3435
35- /*
36- * This is the default value when no origin is provided or when it is 'all'.
37- *
38- * The $origin is used as part of the cache key. Changes here need to account
39- * for clearing the cache appropriately.
40- */
36+ // This is the default value when no origin is provided or when it is 'all'.
4137 $ origin = 'custom ' ;
4238 if ( isset ( $ context ['origin ' ] ) && 'base ' === $ context ['origin ' ] ) {
4339 $ origin = 'theme ' ;
4440 }
4541
46- /*
47- * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
48- * See `wp_cache_add_non_persistent_groups` in src/wp-includes/load.php and other places.
49- *
50- * The rationale for this is to make sure derived data from theme.json
51- * is always fresh from the potential modifications done via hooks
52- * that can use dynamic data (modify the stylesheet depending on some option,
53- * settings depending on user permissions, etc.).
54- * See some of the existing hooks to modify theme.json behavior:
55- * https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
56- *
57- * A different alternative considered was to invalidate the cache upon certain
58- * events such as options add/update/delete, user meta, etc.
59- * It was judged not enough, hence this approach.
60- * See https://github.com/WordPress/gutenberg/pull/45372
61- */
62- $ cache_group = 'theme_json ' ;
63- $ cache_key = 'wp_get_global_settings_ ' . $ origin ;
64-
65- /*
66- * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
67- * developer's workflow.
68- */
69- $ can_use_cached = ! wp_is_development_mode ( 'theme ' );
70-
71- $ settings = false ;
72- if ( $ can_use_cached ) {
73- $ settings = wp_cache_get ( $ cache_key , $ cache_group );
74- }
75-
76- if ( false === $ settings ) {
77- $ settings = WP_Theme_JSON_Resolver ::get_merged_data ( $ origin )->get_settings ();
78- if ( $ can_use_cached ) {
79- wp_cache_set ( $ cache_key , $ settings , $ cache_group );
80- }
81- }
42+ $ settings = WP_Theme_JSON_Resolver ::get_merged_data ( $ origin )->get_settings ();
8243
8344 return _wp_array_get ( $ settings , $ path , $ settings );
8445}
@@ -452,8 +413,6 @@ function wp_theme_has_theme_json() {
452413function wp_clean_theme_json_cache () {
453414 wp_cache_delete ( 'wp_get_global_stylesheet ' , 'theme_json ' );
454415 wp_cache_delete ( 'wp_get_global_styles_svg_filters ' , 'theme_json ' );
455- wp_cache_delete ( 'wp_get_global_settings_custom ' , 'theme_json ' );
456- wp_cache_delete ( 'wp_get_global_settings_theme ' , 'theme_json ' );
457416 wp_cache_delete ( 'wp_get_global_styles_custom_css ' , 'theme_json ' );
458417 wp_cache_delete ( 'wp_get_theme_data_template_parts ' , 'theme_json ' );
459418 WP_Theme_JSON_Resolver ::clean_cached_data ();
0 commit comments