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/block-template-utils.php

    r54761 r54817  
    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();
     
    711711    $theme          = $terms[0]->name;
    712712    $template_file  = _get_block_template_file( $post->post_type, $post->post_name );
    713     $has_theme_file = wp_get_theme()->get_stylesheet() === $theme && null !== $template_file;
     713    $has_theme_file = get_stylesheet() === $theme && null !== $template_file;
    714714
    715715    $origin           = get_post_meta( $post->ID, 'origin', true );
     
    908908                'taxonomy' => 'wp_theme',
    909909                'field'    => 'name',
    910                 'terms'    => wp_get_theme()->get_stylesheet(),
     910                'terms'    => get_stylesheet(),
    911911            ),
    912912        ),
     
    974974
    975975            $is_not_custom   = false === array_search(
    976                 wp_get_theme()->get_stylesheet() . '//' . $template_file['slug'],
     976                get_stylesheet() . '//' . $template_file['slug'],
    977977                wp_list_pluck( $query_result, 'id' ),
    978978                true
     
    11151115    list( $theme, $slug ) = $parts;
    11161116
    1117     if ( wp_get_theme()->get_stylesheet() !== $theme ) {
     1117    if ( get_stylesheet() !== $theme ) {
    11181118        /** This filter is documented in wp-includes/block-template-utils.php */
    11191119        return apply_filters( 'get_block_file_template', null, $id, $template_type );
Note: See TracChangeset for help on using the changeset viewer.