Skip to content

Commit

Permalink
Fix the special handling for the first style in core blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Sep 12, 2022
1 parent af28c1b commit a6b0e7d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
return false;
}

$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 );
if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) {
$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
$theme_path_norm = wp_normalize_path( get_theme_file_path() );
$is_core_block_first_style = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ) && $index === 0;
if ( $is_core_block_first_style && ! wp_should_load_separate_core_block_assets() ) {
return false;
}

Expand All @@ -196,14 +196,14 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
}

$style_path = remove_block_asset_path_prefix( $style_handle );
if ( $style_handle === $style_path && ! $is_core_block ) {
if ( $style_handle === $style_path && ! $is_core_block_first_style ) {
return $style_handle;
}

// Check whether styles should have a ".min" suffix or not.
$suffix = SCRIPT_DEBUG ? '' : '.min';
$style_uri = plugins_url( $style_path, $metadata['file'] );
if ( $is_core_block ) {
if ( $is_core_block_first_style ) {
$style_path = "style$suffix.css";
$style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" );
}
Expand All @@ -219,7 +219,7 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
$block_dir = dirname( $metadata['file'] );
$style_file = realpath( "$block_dir/$style_path" );
$has_style_file = false !== $style_file;
$version = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false;
$version = ! $is_core_block_first_style && isset( $metadata['version'] ) ? $metadata['version'] : false;
$style_uri = $has_style_file ? $style_uri : false;
$result = wp_register_style(
$style_handle,
Expand Down

0 comments on commit a6b0e7d

Please sign in to comment.