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
This commit is contained in:
antpb 2023-08-24 19:38:19 +00:00
parent c8aa89e42d
commit b6368060a5
2 changed files with 5 additions and 2 deletions

View File

@ -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();

View File

@ -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.