Skip to content

Commit 6f6bd30

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@58185 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5dc0cc0 commit 6f6bd30

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/wp-includes/class-wp-theme-json-data.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,15 @@ public function update_with( $new_data ) {
6969
public function get_data() {
7070
return $this->theme_json->get_raw_data();
7171
}
72+
73+
/**
74+
* Returns theme JSON object.
75+
*
76+
* @since 6.6.0
77+
*
78+
* @return WP_Theme_JSON The theme JSON structure stored in this data object.
79+
*/
80+
public function get_theme_json() {
81+
return $this->theme_json;
82+
}
7283
}

src/wp-includes/class-wp-theme-json-resolver.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ public static function get_core_data() {
173173
* @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
174174
*/
175175
$theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data( $config, 'default' ) );
176-
$config = $theme_json->get_data();
177-
static::$core = new WP_Theme_JSON( $config, 'default' );
176+
static::$core = $theme_json->get_theme_json();
178177

179178
return static::$core;
180179
}
@@ -255,8 +254,7 @@ public static function get_theme_data( $deprecated = array(), $options = array()
255254
* @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
256255
*/
257256
$theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) );
258-
$theme_json_data = $theme_json->get_data();
259-
static::$theme = new WP_Theme_JSON( $theme_json_data );
257+
static::$theme = $theme_json->get_theme_json();
260258

261259
if ( $wp_theme->parent() ) {
262260
// Get parent theme.json.
@@ -387,9 +385,7 @@ public static function get_block_data() {
387385
* @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
388386
*/
389387
$theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) );
390-
$config = $theme_json->get_data();
391-
392-
static::$blocks = new WP_Theme_JSON( $config, 'blocks' );
388+
static::$blocks = $theme_json->get_theme_json();
393389
return static::$blocks;
394390
}
395391

@@ -523,8 +519,7 @@ public static function get_user_data() {
523519
* @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
524520
*/
525521
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) );
526-
$config = $theme_json->get_data();
527-
return new WP_Theme_JSON( $config, 'custom' );
522+
return $theme_json->get_theme_json();
528523
}
529524

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

544539
/** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */
545540
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) );
546-
$config = $theme_json->get_data();
547-
static::$user = new WP_Theme_JSON( $config, 'custom' );
541+
static::$user = $theme_json->get_theme_json();
548542

549543
return static::$user;
550544
}

0 commit comments

Comments
 (0)