Skip to content

Commit

Permalink
Editor: Remove additional calls to WP_Theme_JSON::_construct.
Browse files Browse the repository at this point in the history
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.


git-svn-id: https://develop.svn.wordpress.org/trunk@58185 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
joemcgill committed May 23, 2024
1 parent 5dc0cc0 commit 6f6bd30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/wp-includes/class-wp-theme-json-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@ public function update_with( $new_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;
}
}
16 changes: 5 additions & 11 deletions src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public static function get_core_data() {
* @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;
}
Expand Down Expand Up @@ -255,8 +254,7 @@ public static function get_theme_data( $deprecated = array(), $options = array()
* @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.
Expand Down Expand Up @@ -387,9 +385,7 @@ public static function get_block_data() {
* @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;
}

Expand Down Expand Up @@ -523,8 +519,7 @@ public static function get_user_data() {
* @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();
}

/*
Expand All @@ -543,8 +538,7 @@ public static function get_user_data() {

/** 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;
}
Expand Down

0 comments on commit 6f6bd30

Please sign in to comment.