diff --git a/src/wp-includes/class-wp-theme-json-resolver.php b/src/wp-includes/class-wp-theme-json-resolver.php index b1f15897b1af5..ac36f2d4a0f6a 100644 --- a/src/wp-includes/class-wp-theme-json-resolver.php +++ b/src/wp-includes/class-wp-theme-json-resolver.php @@ -57,6 +57,14 @@ class WP_Theme_JSON_Resolver { */ protected static $theme = null; + /** + * Container for data coming from the theme with supports. + * + * @since 6.1.2 + * @var WP_Theme_JSON + */ + protected static $with_theme_supports = null; + /** * Whether or not the theme supports theme.json. * @@ -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. @@ -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; } /** @@ -638,6 +650,8 @@ protected static function get_file_path_from_theme( $file_name, $template = fals * and `$i18n_schema` variables to reset. * @since 6.1.0 Added the `$blocks` and `$blocks_cache` variables * to reset. + * @since 6.1.2 Added the `$with_theme_supports` variables + * to reset. */ public static function clean_cached_data() { static::$core = null; @@ -649,6 +663,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; diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index e9ca31f5f7908..e3b568290f363 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -346,13 +346,15 @@ add_action( 'init', '_register_core_block_patterns_and_categories' ); add_action( 'init', 'check_theme_switched', 99 ); add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 ); -add_action( 'switch_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) ); -add_action( 'start_previewing_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) ); add_action( 'after_switch_theme', '_wp_menus_changed' ); add_action( 'after_switch_theme', '_wp_sidebars_changed' ); add_action( 'wp_print_styles', 'print_emoji_styles' ); add_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); +foreach ( array( 'switch_theme', 'start_previewing_theme', 'add_theme_support', 'remove_theme_support' ) as $action ) { + add_action( $action, array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) ); +} + if ( isset( $_GET['replytocom'] ) ) { add_filter( 'wp_robots', 'wp_robots_no_robots' ); } diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 61d5c13284a10..21c3ee191cd11 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -2835,6 +2835,16 @@ function add_theme_support( $feature, ...$args ) { } $_wp_theme_features[ $feature ] = $args; + + /** + * Fires after theme support is added. + * + * @since 6.1.2 + * + * @param string $feature The feature being added. + * @param mixed $args Optional extra arguments to pass along with certain features. + */ + do_action( 'add_theme_support', $feature, $args ); } /** @@ -3033,6 +3043,15 @@ function _remove_theme_support( $feature ) { unset( $_wp_theme_features[ $feature ] ); + /** + * Fires after theme support is removed. + * + * @since 6.1.2 + * + * @param string $feature The feature being added. + */ + do_action( 'remove_theme_support', $feature ); + return true; } diff --git a/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php b/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php index 710f77d0caf0d..ebb61415a164c 100644 --- a/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php +++ b/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php @@ -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'] ); } @@ -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();