diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 9fea12a8d3e99..aae319ea944ec 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -1934,6 +1934,15 @@ protected static function compute_style_properties( $styles, $settings = array() return $declarations; } + // The global settings can include dynamic data related to typography. We need evaluate it so that the cache is invalidated when it changes. + $args = array( func_get_args(), wp_get_global_settings() ); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed + $cache_key = 'compute_style_properties_' . md5( wp_json_encode( $args ) ); + $cache = wp_cache_get( $cache_key, 'wp-styles' ); + + if ( $cache ) { + return $cache; + } + $root_variable_duplicates = array(); foreach ( $properties as $css_property => $value_path ) { @@ -2000,6 +2009,8 @@ protected static function compute_style_properties( $styles, $settings = array() } } + wp_cache_set( $cache_key, $declarations, 'wp-styles', DAY_IN_SECONDS ); + return $declarations; }