Make WordPress Core


Ignore:
Timestamp:
11/11/2022 04:24:47 PM (2 years ago)
Author:
spacedmonkey
Message:

Themes: Reduce usage of wp_get_theme function.

Calling the wp_get_theme function creates a instance of the WP_Theme class. This can be a performance issue, if all you need is one property of the class instance. This change replaces the usage of wp_get_theme()->get_stylesheet() with get_stylesheet() to improve performance.

Props spacedmonkey, flixos90, peterwilsoncc, desrosj.
Fixes #57057.

File:
1 edited

Legend:

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

    r54799 r54817  
    244244        }
    245245
    246         $options = wp_parse_args( $options, array( 'with_supports' => true ) );
     246        $options  = wp_parse_args( $options, array( 'with_supports' => true ) );
    247247
    248248        if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) {
    249249            $theme_json_file = static::get_file_path_from_theme( 'theme.json' );
     250            $wp_theme        = wp_get_theme();
    250251            if ( '' !== $theme_json_file ) {
    251252                $theme_json_data = static::read_json_file( $theme_json_file );
    252                 $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
     253                $theme_json_data = static::translate( $theme_json_data, $wp_theme->get( 'TextDomain' ) );
    253254            } else {
    254255                $theme_json_data = array();
     
    266267            static::$theme   = new WP_Theme_JSON( $theme_json_data );
    267268
    268             if ( wp_get_theme()->parent() ) {
     269            if ( $wp_theme->parent() ) {
    269270                // Get parent theme.json.
    270271                $parent_theme_json_file = static::get_file_path_from_theme( 'theme.json', true );
    271272                if ( '' !== $parent_theme_json_file ) {
    272273                    $parent_theme_json_data = static::read_json_file( $parent_theme_json_file );
    273                     $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) );
     274                    $parent_theme_json_data = static::translate( $parent_theme_json_data, $wp_theme->parent()->get( 'TextDomain' ) );
    274275                    $parent_theme           = new WP_Theme_JSON( $parent_theme_json_data );
    275276
Note: See TracChangeset for help on using the changeset viewer.