diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 0d6d84fdef..261394bb65 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -127,12 +127,14 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { ); return false; } + // Path needs to be normalized to work in Windows env. $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); $theme_path_norm = wp_normalize_path( get_theme_file_path() ); $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ); - $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); - $is_theme_block = 0 === strpos( $script_path_norm, $theme_path_norm ); + + $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); + $is_theme_block = 0 === strpos( $script_path_norm, $theme_path_norm ); $script_uri = plugins_url( $script_path, $metadata['file'] ); if ( $is_core_block ) { @@ -181,8 +183,8 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) { } $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); - $theme_path_norm = wp_normalize_path( get_theme_file_path() ); - $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); + + $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); // Skip registering individual styles for each core block when a bundled version provided. if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) { return false; @@ -212,15 +214,25 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) { if ( $is_core_block ) { $style_path = "style$suffix.css"; } + $style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) ); $has_style_file = '' !== $style_path_norm; + if ( $has_style_file ) { - $style_uri = plugins_url( $style_path, $metadata['file'] ); + $style_uri = plugins_url( $style_path, $metadata['file'] ); + + // Cache $theme_path_norm to avoid calling get_theme_file_path() multiple times. + static $theme_path_norm = ''; + if ( ! $theme_path_norm ) { + $theme_path_norm = wp_normalize_path( get_theme_file_path() ); + } + $is_theme_block = str_starts_with( $style_path_norm, $theme_path_norm ); + if ( $is_theme_block ) { $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) ); } elseif ( $is_core_block ) { - $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" ); + $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" ); } } else { $style_uri = false;