Make WordPress Core

Changeset 54818


Ignore:
Timestamp:
11/11/2022 04:29:27 PM (4 years ago)
Author:
desrosj
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.
Merges [54817] to the 6.1 branch.
Fixes #57057.

Location:
branches/6.1
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/6.1

  • branches/6.1/src/wp-admin/site-editor.php

    r54792 r54818  
    102102
    103103$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
    104 $active_theme            = wp_get_theme()->get_stylesheet();
     104$active_theme            = get_stylesheet();
    105105$preload_paths           = array(
    106106        array( '/wp/v2/media', 'OPTIONS' ),
  • branches/6.1/src/wp-includes/block-template-utils.php

    r54767 r54818  
    438438                        ! isset( $block['attrs']['theme'] )
    439439                ) {
    440                         $block['attrs']['theme'] = wp_get_theme()->get_stylesheet();
     440                        $block['attrs']['theme'] = get_stylesheet();
    441441                        $has_updated_content     = true;
    442442                }
    … …  
    500500        $default_template_types = get_default_block_template_types();
    501501        $template_content       = file_get_contents( $template_file['path'] );
    502         $theme                  = wp_get_theme()->get_stylesheet();
     502        $theme                  = get_stylesheet();
    503503
    504504        $template                 = new WP_Block_Template();
    … …  
    707707        $theme          = $terms[0]->name;
    708708        $template_file  = _get_block_template_file( $post->post_type, $post->post_name );
    709         $has_theme_file = wp_get_theme()->get_stylesheet() === $theme && null !== $template_file;
     709        $has_theme_file = get_stylesheet() === $theme && null !== $template_file;
    710710
    711711        $origin           = get_post_meta( $post->ID, 'origin', true );
    … …  
    904904                                'taxonomy' => 'wp_theme',
    905905                                'field'    => 'name',
    906                                 'terms'    => wp_get_theme()->get_stylesheet(),
     906                                'terms'    => get_stylesheet(),
    907907                        ),
    908908                ),
    … …  
    970970
    971971                        $is_not_custom   = false === array_search(
    972                                 wp_get_theme()->get_stylesheet() . '//' . $template_file['slug'],
     972                                get_stylesheet() . '//' . $template_file['slug'],
    973973                                wp_list_pluck( $query_result, 'id' ),
    974974                                true
    … …  
    11111111        list( $theme, $slug ) = $parts;
    11121112
    1113         if ( wp_get_theme()->get_stylesheet() !== $theme ) {
     1113        if ( get_stylesheet() !== $theme ) {
    11141114                /** This filter is documented in wp-includes/block-template-utils.php */
    11151115                return apply_filters( 'get_block_file_template', null, $id, $template_type );
  • branches/6.1/src/wp-includes/block-template.php

    r54792 r54818  
    146146        // Find all potential templates 'wp_template' post matching the hierarchy.
    147147        $query     = array(
    148                 'theme'    => wp_get_theme()->get_stylesheet(),
     148                'theme'    => get_stylesheet(),
    149149                'slug__in' => $slugs,
    150150        );
  • branches/6.1/src/wp-includes/blocks/template-part.php

    r54812 r54818  
    2323                isset( $attributes['slug'] ) &&
    2424                isset( $attributes['theme'] ) &&
    25                 wp_get_theme()->get_stylesheet() === $attributes['theme']
     25                get_stylesheet() === $attributes['theme']
    2626        ) {
    2727                $template_part_id    = $attributes['theme'] . '//' . $attributes['slug'];
  • branches/6.1/src/wp-includes/class-wp-theme-json-resolver.php

    r54800 r54818  
    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
  • branches/6.1/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php

    r53760 r54818  
    565565         */
    566566        public function get_theme_item( $request ) {
    567                 if ( wp_get_theme()->get_stylesheet() !== $request['stylesheet'] ) {
     567                if ( get_stylesheet() !== $request['stylesheet'] ) {
    568568                        // This endpoint only supports the active theme for now.
    569569                        return new WP_Error(
    … …  
    639639         */
    640640        public function get_theme_items( $request ) {
    641                 if ( wp_get_theme()->get_stylesheet() !== $request['stylesheet'] ) {
     641                if ( get_stylesheet() !== $request['stylesheet'] ) {
    642642                        // This endpoint only supports the active theme for now.
    643643                        return new WP_Error(
  • branches/6.1/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php

    r54356 r54818  
    529529                        $changes->post_status = 'publish';
    530530                        $changes->tax_input   = array(
    531                                 'wp_theme' => isset( $request['theme'] ) ? $request['theme'] : wp_get_theme()->get_stylesheet(),
     531                                'wp_theme' => isset( $request['theme'] ) ? $request['theme'] : get_stylesheet(),
    532532                        );
    533533                } elseif ( 'custom' !== $template->source ) {
  • branches/6.1/src/wp-includes/theme-templates.php

    r53331 r54818  
    2828        $terms = get_the_terms( $post_id, 'wp_theme' );
    2929        if ( ! is_array( $terms ) || ! count( $terms ) ) {
    30                 wp_set_post_terms( $post_id, wp_get_theme()->get_stylesheet(), 'wp_theme' );
     30                wp_set_post_terms( $post_id, get_stylesheet(), 'wp_theme' );
    3131        }
    3232}
    … …  
    6161         * to the entity. So for now we use the currently activated theme for creation.
    6262         */
    63         $theme = wp_get_theme()->get_stylesheet();
     63        $theme = get_stylesheet();
    6464        $terms = get_the_terms( $post_ID, 'wp_theme' );
    6565        if ( $terms && ! is_wp_error( $terms ) ) {
Note: See TracChangeset for help on using the changeset viewer.