Make WordPress Core

Changeset 58185


Ignore:
Timestamp:
05/23/2024 04:12:31 PM (2 years ago)
Author:
joemcgill
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json-data.php

    r56547 r58185  
    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}
  • trunk/src/wp-includes/class-wp-theme-json-resolver.php

    r57885 r58185  
    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;
     
    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() ) {
     
    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        }
     
    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
     
    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;
Note: See TracChangeset for help on using the changeset viewer.