From dd8c83e6a169eee7f8f09ee86b8932a1d4b38f9a Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Fri, 3 Nov 2023 09:58:02 +0000 Subject: [PATCH] Only use cache if not in dev mode for theme. Ensure we do not process empty `$styles` --- src/wp-includes/class-wp-theme-json.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 2c1082672e203..dc67613b08fdc 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -1925,14 +1925,6 @@ protected static function flatten_tree( $tree, $prefix = '', $token = '--' ) { * @return array Returns the modified $declarations. */ protected static function compute_style_properties( $styles, $settings = array(), $properties = null, $theme_json = null, $selector = null, $use_root_padding = null ) { - $args = func_get_args(); - $cache_key = 'compute_style_properties_' . md5( wp_json_encode( $args ) ); - $cache = wp_cache_get( $cache_key, 'wp-styles' ); - - if ( $cache ) { - return $cache; - } - if ( null === $properties ) { $properties = static::PROPERTIES_METADATA; } @@ -1942,6 +1934,16 @@ protected static function compute_style_properties( $styles, $settings = array() return $declarations; } + $can_use_cached = ! wp_is_development_mode( 'theme' ); + + $args = func_get_args(); + $cache_key = 'compute_style_properties_' . md5( wp_json_encode( $args ) ); + $cache = wp_cache_get( $cache_key, 'wp-styles' ); + + if ( $can_use_cached && $cache ) { + return $cache; + } + $root_variable_duplicates = array(); foreach ( $properties as $css_property => $value_path ) { @@ -2008,7 +2010,9 @@ protected static function compute_style_properties( $styles, $settings = array() } } - wp_cache_set( $cache_key, $declarations, 'wp-styles' ); + if ( $can_use_cached ) { + wp_cache_set( $cache_key, $declarations, 'wp-styles', DAY_IN_SECONDS ); + } return $declarations; }