Skip to content

Commit

Permalink
Only use cache if not in dev mode for theme. Ensure we do not process…
Browse files Browse the repository at this point in the history
… empty `$styles`
  • Loading branch information
pereirinha committed Nov 3, 2023
1 parent c9b36ea commit dd8c83e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit dd8c83e

Please sign in to comment.