Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved caching. #3624

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
19 changes: 16 additions & 3 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.
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
*
* @since 6.1.1
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
* @var WP_Theme_JSON
*/
protected static $with_theme_supports = null;

/**
* Whether or not the theme supports theme.json.
*
Expand Down Expand Up @@ -288,6 +296,10 @@ public static function get_theme_data( $deprecated = array(), $options = array()
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 @@ -323,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 );
$with_theme_supports->merge( static::$theme );
return $with_theme_supports;
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 @@ -649,6 +661,7 @@ public static function clean_cached_data() {
'user' => array(),
);
static::$theme = null;
static::$with_theme_supports = null;
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
static::$user = null;
static::$user_custom_post_type_id = null;
static::$theme_has_support = null;
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/theme/wpGetGlobalStylesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function set_up() {

// Clear caches.
wp_clean_themes_cache();
WP_Theme_JSON_Resolver::clean_cached_data();
unset( $GLOBALS['wp_themes'] );
}

Expand All @@ -49,6 +50,7 @@ public function tear_down() {
remove_filter( 'template_root', array( $this, 'filter_set_theme_root' ) );

wp_clean_themes_cache();
WP_Theme_JSON_Resolver::clean_cached_data();
unset( $GLOBALS['wp_themes'] );

parent::tear_down();
Expand Down