From bdebc89143069e1b5f4c3357c320b27c9b18543c Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Thu, 23 May 2024 16:14:13 +0000 Subject: [PATCH] Editor: Remove additional calls to `WP_Theme_JSON::_construct`. This improves performance of the `WP_Theme_JSON_Resolver` class by avoiding redundant construction of `WP_Theme_JSON` objects for each origin. Props thekt12, joemcgill, swissspidy, audrasjb, oandregal. Fixes #61112. Built from https://develop.svn.wordpress.org/trunk@58185 git-svn-id: http://core.svn.wordpress.org/trunk@57648 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json-data.php | 11 +++++++++++ wp-includes/class-wp-theme-json-resolver.php | 16 +++++----------- wp-includes/version.php | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/wp-includes/class-wp-theme-json-data.php b/wp-includes/class-wp-theme-json-data.php index 6aa8a3971c..30dab47185 100644 --- a/wp-includes/class-wp-theme-json-data.php +++ b/wp-includes/class-wp-theme-json-data.php @@ -69,4 +69,15 @@ class WP_Theme_JSON_Data { public function get_data() { return $this->theme_json->get_raw_data(); } + + /** + * Returns theme JSON object. + * + * @since 6.6.0 + * + * @return WP_Theme_JSON The theme JSON structure stored in this data object. + */ + public function get_theme_json() { + return $this->theme_json; + } } diff --git a/wp-includes/class-wp-theme-json-resolver.php b/wp-includes/class-wp-theme-json-resolver.php index 3ad5ecf0c4..59c5f54b96 100644 --- a/wp-includes/class-wp-theme-json-resolver.php +++ b/wp-includes/class-wp-theme-json-resolver.php @@ -173,8 +173,7 @@ class WP_Theme_JSON_Resolver { * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data( $config, 'default' ) ); - $config = $theme_json->get_data(); - static::$core = new WP_Theme_JSON( $config, 'default' ); + static::$core = $theme_json->get_theme_json(); return static::$core; } @@ -255,8 +254,7 @@ class WP_Theme_JSON_Resolver { * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); - $theme_json_data = $theme_json->get_data(); - static::$theme = new WP_Theme_JSON( $theme_json_data ); + static::$theme = $theme_json->get_theme_json(); if ( $wp_theme->parent() ) { // Get parent theme.json. @@ -387,9 +385,7 @@ class WP_Theme_JSON_Resolver { * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) ); - $config = $theme_json->get_data(); - - static::$blocks = new WP_Theme_JSON( $config, 'blocks' ); + static::$blocks = $theme_json->get_theme_json(); return static::$blocks; } @@ -523,8 +519,7 @@ class WP_Theme_JSON_Resolver { * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); - $config = $theme_json->get_data(); - return new WP_Theme_JSON( $config, 'custom' ); + return $theme_json->get_theme_json(); } /* @@ -543,8 +538,7 @@ class WP_Theme_JSON_Resolver { /** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); - $config = $theme_json->get_data(); - static::$user = new WP_Theme_JSON( $config, 'custom' ); + static::$user = $theme_json->get_theme_json(); return static::$user; } diff --git a/wp-includes/version.php b/wp-includes/version.php index e0f42df094..e190b872dc 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58184'; +$wp_version = '6.6-alpha-58185'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.