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. Built from https://develop.svn.wordpress.org/trunk@54817 git-svn-id: http://core.svn.wordpress.org/trunk@54369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4e492ffe61
commit
8ea348f6db
|
@ -101,7 +101,7 @@ if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) {
|
|||
}
|
||||
|
||||
$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
|
||||
$active_theme = wp_get_theme()->get_stylesheet();
|
||||
$active_theme = get_stylesheet();
|
||||
$preload_paths = array(
|
||||
array( '/wp/v2/media', 'OPTIONS' ),
|
||||
'/wp/v2/types?context=view',
|
||||
|
|
|
@ -437,7 +437,7 @@ function _inject_theme_attribute_in_block_template_content( $template_content )
|
|||
'core/template-part' === $block['blockName'] &&
|
||||
! isset( $block['attrs']['theme'] )
|
||||
) {
|
||||
$block['attrs']['theme'] = wp_get_theme()->get_stylesheet();
|
||||
$block['attrs']['theme'] = get_stylesheet();
|
||||
$has_updated_content = true;
|
||||
}
|
||||
}
|
||||
|
@ -499,7 +499,7 @@ function _remove_theme_attribute_in_block_template_content( $template_content )
|
|||
function _build_block_template_result_from_file( $template_file, $template_type ) {
|
||||
$default_template_types = get_default_block_template_types();
|
||||
$template_content = file_get_contents( $template_file['path'] );
|
||||
$theme = wp_get_theme()->get_stylesheet();
|
||||
$theme = get_stylesheet();
|
||||
|
||||
$template = new WP_Block_Template();
|
||||
$template->id = $theme . '//' . $template_file['slug'];
|
||||
|
@ -710,7 +710,7 @@ function _build_block_template_result_from_post( $post ) {
|
|||
|
||||
$theme = $terms[0]->name;
|
||||
$template_file = _get_block_template_file( $post->post_type, $post->post_name );
|
||||
$has_theme_file = wp_get_theme()->get_stylesheet() === $theme && null !== $template_file;
|
||||
$has_theme_file = get_stylesheet() === $theme && null !== $template_file;
|
||||
|
||||
$origin = get_post_meta( $post->ID, 'origin', true );
|
||||
$is_wp_suggestion = get_post_meta( $post->ID, 'is_wp_suggestion', true );
|
||||
|
@ -907,7 +907,7 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
|||
array(
|
||||
'taxonomy' => 'wp_theme',
|
||||
'field' => 'name',
|
||||
'terms' => wp_get_theme()->get_stylesheet(),
|
||||
'terms' => get_stylesheet(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -973,7 +973,7 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
|||
}
|
||||
|
||||
$is_not_custom = false === array_search(
|
||||
wp_get_theme()->get_stylesheet() . '//' . $template_file['slug'],
|
||||
get_stylesheet() . '//' . $template_file['slug'],
|
||||
wp_list_pluck( $query_result, 'id' ),
|
||||
true
|
||||
);
|
||||
|
@ -1114,7 +1114,7 @@ function get_block_file_template( $id, $template_type = 'wp_template' ) {
|
|||
}
|
||||
list( $theme, $slug ) = $parts;
|
||||
|
||||
if ( wp_get_theme()->get_stylesheet() !== $theme ) {
|
||||
if ( get_stylesheet() !== $theme ) {
|
||||
/** This filter is documented in wp-includes/block-template-utils.php */
|
||||
return apply_filters( 'get_block_file_template', null, $id, $template_type );
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ function resolve_block_template( $template_type, $template_hierarchy, $fallback_
|
|||
|
||||
// Find all potential templates 'wp_template' post matching the hierarchy.
|
||||
$query = array(
|
||||
'theme' => wp_get_theme()->get_stylesheet(),
|
||||
'theme' => get_stylesheet(),
|
||||
'slug__in' => $slugs,
|
||||
);
|
||||
$templates = get_block_templates( $query );
|
||||
|
|
|
@ -22,7 +22,7 @@ function render_block_core_template_part( $attributes ) {
|
|||
if (
|
||||
isset( $attributes['slug'] ) &&
|
||||
isset( $attributes['theme'] ) &&
|
||||
wp_get_theme()->get_stylesheet() === $attributes['theme']
|
||||
get_stylesheet() === $attributes['theme']
|
||||
) {
|
||||
$template_part_id = $attributes['theme'] . '//' . $attributes['slug'];
|
||||
$template_part_query = new WP_Query(
|
||||
|
|
|
@ -247,9 +247,10 @@ class WP_Theme_JSON_Resolver {
|
|||
|
||||
if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) {
|
||||
$theme_json_file = static::get_file_path_from_theme( 'theme.json' );
|
||||
$wp_theme = wp_get_theme();
|
||||
if ( '' !== $theme_json_file ) {
|
||||
$theme_json_data = static::read_json_file( $theme_json_file );
|
||||
$theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
|
||||
$theme_json_data = static::translate( $theme_json_data, $wp_theme->get( 'TextDomain' ) );
|
||||
} else {
|
||||
$theme_json_data = array();
|
||||
}
|
||||
|
@ -265,12 +266,12 @@ class WP_Theme_JSON_Resolver {
|
|||
$theme_json_data = $theme_json->get_data();
|
||||
static::$theme = new WP_Theme_JSON( $theme_json_data );
|
||||
|
||||
if ( wp_get_theme()->parent() ) {
|
||||
if ( $wp_theme->parent() ) {
|
||||
// Get parent theme.json.
|
||||
$parent_theme_json_file = static::get_file_path_from_theme( 'theme.json', true );
|
||||
if ( '' !== $parent_theme_json_file ) {
|
||||
$parent_theme_json_data = static::read_json_file( $parent_theme_json_file );
|
||||
$parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) );
|
||||
$parent_theme_json_data = static::translate( $parent_theme_json_data, $wp_theme->parent()->get( 'TextDomain' ) );
|
||||
$parent_theme = new WP_Theme_JSON( $parent_theme_json_data );
|
||||
|
||||
/*
|
||||
|
|
|
@ -564,7 +564,7 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_theme_item( $request ) {
|
||||
if ( wp_get_theme()->get_stylesheet() !== $request['stylesheet'] ) {
|
||||
if ( get_stylesheet() !== $request['stylesheet'] ) {
|
||||
// This endpoint only supports the active theme for now.
|
||||
return new WP_Error(
|
||||
'rest_theme_not_found',
|
||||
|
@ -638,7 +638,7 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_theme_items( $request ) {
|
||||
if ( wp_get_theme()->get_stylesheet() !== $request['stylesheet'] ) {
|
||||
if ( get_stylesheet() !== $request['stylesheet'] ) {
|
||||
// This endpoint only supports the active theme for now.
|
||||
return new WP_Error(
|
||||
'rest_theme_not_found',
|
||||
|
|
|
@ -528,7 +528,7 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
|||
$changes->post_type = $this->post_type;
|
||||
$changes->post_status = 'publish';
|
||||
$changes->tax_input = array(
|
||||
'wp_theme' => isset( $request['theme'] ) ? $request['theme'] : wp_get_theme()->get_stylesheet(),
|
||||
'wp_theme' => isset( $request['theme'] ) ? $request['theme'] : get_stylesheet(),
|
||||
);
|
||||
} elseif ( 'custom' !== $template->source ) {
|
||||
$changes->post_name = $template->slug;
|
||||
|
|
|
@ -27,7 +27,7 @@ function wp_set_unique_slug_on_create_template_part( $post_id ) {
|
|||
|
||||
$terms = get_the_terms( $post_id, 'wp_theme' );
|
||||
if ( ! is_array( $terms ) || ! count( $terms ) ) {
|
||||
wp_set_post_terms( $post_id, wp_get_theme()->get_stylesheet(), 'wp_theme' );
|
||||
wp_set_post_terms( $post_id, get_stylesheet(), 'wp_theme' );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ function wp_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_ID
|
|||
* in the case of new entities since is too early in the process to have been saved
|
||||
* to the entity. So for now we use the currently activated theme for creation.
|
||||
*/
|
||||
$theme = wp_get_theme()->get_stylesheet();
|
||||
$theme = get_stylesheet();
|
||||
$terms = get_the_terms( $post_ID, 'wp_theme' );
|
||||
if ( $terms && ! is_wp_error( $terms ) ) {
|
||||
$theme = $terms[0]->name;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.2-alpha-54815';
|
||||
$wp_version = '6.2-alpha-54817';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue