Make WordPress Core

Changeset 56455


Ignore:
Timestamp:
08/24/2023 07:36:16 PM (15 months ago)
Author:
antpb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r56403 r56455  
    155155    $is_theme_block        = ( $is_parent_theme_block || $is_child_theme_block );
    156156
    157     $script_uri = plugins_url( $script_path, $metadata['file'] );
     157    $script_uri = '';
    158158    if ( $is_core_block ) {
    159159        $script_uri = includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) );
     
    163163            ? get_theme_file_uri( str_replace( $template_path_norm, '', $script_path_norm ) )
    164164            : get_theme_file_uri( str_replace( $stylesheet_path_norm, '', $script_path_norm ) );
     165    } else {
     166        // Fallback to plugins_url().
     167        $script_uri = plugins_url( $script_path, $metadata['file'] );
    165168    }
    166169
Note: See TracChangeset for help on using the changeset viewer.