From b6368060a56ba3e05caba9c12f75685ac4ed7c95 Mon Sep 17 00:00:00 2001 From: antpb Date: Thu, 24 Aug 2023 19:38:19 +0000 Subject: [PATCH] Performance: Add fallback for `$script_uri` to prevent firing `plugins_url()` unnecessarily. Previously, in `register_block_script_handle()` the `$script_uri` variable initialized with a `plugins_url()` call that was reported to invoke four times. In this patch the var is initialized as a blank string with a fallback to use the `plugins_url()` if the other intended conditions are not met. Props mukesh27, daxelrod, adamsilverstein, davidbaumwald. Fixes #59181. Built from https://develop.svn.wordpress.org/trunk@56455 git-svn-id: http://core.svn.wordpress.org/trunk@55967 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 5 ++++- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 5f48c0af59..4d3a34e34f 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -154,7 +154,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { $is_child_theme_block = str_starts_with( $script_path_norm, $stylesheet_path_norm ); $is_theme_block = ( $is_parent_theme_block || $is_child_theme_block ); - $script_uri = plugins_url( $script_path, $metadata['file'] ); + $script_uri = ''; if ( $is_core_block ) { $script_uri = includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) ); } elseif ( $is_theme_block ) { @@ -162,6 +162,9 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { $script_uri = $is_parent_theme_block ? get_theme_file_uri( str_replace( $template_path_norm, '', $script_path_norm ) ) : get_theme_file_uri( str_replace( $stylesheet_path_norm, '', $script_path_norm ) ); + } else { + // Fallback to plugins_url(). + $script_uri = plugins_url( $script_path, $metadata['file'] ); } $script_args = array(); diff --git a/wp-includes/version.php b/wp-includes/version.php index e4afd1fc2d..185768f2cb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56454'; +$wp_version = '6.4-alpha-56455'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.