Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Two caches.
  • Loading branch information
spacedmonkey committed Nov 14, 2022
commit 202ee64babbb0977be5e65919d51f162a0cbed13
27 changes: 21 additions & 6 deletions src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class WP_Theme_JSON_Resolver {
*/
protected static $theme = null;

/**
* Container for data coming from the theme with settings.
*
* @since 6.1.1
* @var WP_Theme_JSON
*/
protected static $with_theme_supports = null;

/**
* Whether or not the theme supports theme.json.
*
Expand Down Expand Up @@ -243,9 +251,7 @@ public static function get_theme_data( $deprecated = array(), $options = array()
_deprecated_argument( __METHOD__, '5.9.0' );
}

if ( static::$theme ) {
return static::$theme;
}
$options = wp_parse_args( $options, array( 'with_supports' => true ) );

if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) {
$theme_json_file = static::get_file_path_from_theme( 'theme.json' );
Expand Down Expand Up @@ -286,6 +292,14 @@ public static function get_theme_data( $deprecated = array(), $options = array()
}
}

if ( ! $options['with_supports'] ) {
return static::$theme;
}

if ( null !== static::$with_theme_supports ) {
return static::$with_theme_supports;
}

/*
* We want the presets and settings declared in theme.json
* to override the ones declared via theme supports.
Expand Down Expand Up @@ -321,9 +335,9 @@ public static function get_theme_data( $deprecated = array(), $options = array()
// Classic themes without a theme.json don't support global duotone.
$theme_support_data['settings']['color']['defaultDuotone'] = false;
}
$with_theme_supports = new WP_Theme_JSON( $theme_support_data );
static::$theme->merge( $with_theme_supports );
return static::$theme;
static::$with_theme_supports = new WP_Theme_JSON( $theme_support_data );
static::$with_theme_supports->merge( static::$theme );
return static::$with_theme_supports;
}

/**
Expand Down Expand Up @@ -647,6 +661,7 @@ public static function clean_cached_data() {
'user' => array(),
);
static::$theme = null;
static::$with_theme_supports = null;
static::$user = null;
static::$user_custom_post_type_id = null;
static::$theme_has_support = null;
Expand Down