Skip to content

Commit

Permalink
Implement object cache for gutenberg_get_global_settings (WordPress…
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal authored and mpkelly committed Dec 7, 2022
1 parent 020c67b commit b8415be
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/compat/wordpress-6.2/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,15 @@ function gutenberg_get_global_settings( $path = array(), $context = array() ) {
$origin = 'theme';
}

$settings = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings();
$cache_group = 'theme_json';
$cache_key = 'gutenberg_get_global_settings_' . $origin;
$settings = wp_cache_get( $cache_key, $cache_group );

if ( false === $settings || WP_DEBUG ) {
$settings = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings();
wp_cache_set( $cache_key, $settings, $cache_group );
}

return _wp_array_get( $settings, $path, $settings );
}

Expand All @@ -183,6 +191,7 @@ function gutenberg_get_global_settings( $path = array(), $context = array() ) {
function _gutenberg_clean_theme_json_caches() {
wp_cache_delete( 'wp_theme_has_theme_json', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_stylesheet', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_settings_custom', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_settings_theme', 'theme_json' );
WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data();
}
Expand All @@ -192,6 +201,7 @@ function _gutenberg_clean_theme_json_caches() {
* The data stored under this cache group:
*
* - wp_theme_has_theme_json
* - gutenberg_get_global_settings
* - gutenberg_get_global_stylesheet
*
* There is some hooks consumers can use to modify parts
Expand Down

0 comments on commit b8415be

Please sign in to comment.