Make WordPress Core


Ignore:
Timestamp:
11/11/2022 04:29:27 PM (2 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:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.1

  • 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 );
Note: See TracChangeset for help on using the changeset viewer.