Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/wp-includes/blocks/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,27 @@ static function ( $file ) use ( $normalized_blocks_path ) {
}
}

$register_style = static function ( $name, $filename, $style_handle ) use ( $blocks_url, $suffix, $wp_styles, $files ) {
// Index the file list by path so the lookups below are key-based rather than a full array scan.
$file_index = array_fill_keys( $files, true );

$register_style = static function ( $name, $filename, $style_handle ) use ( $blocks_url, $suffix, $wp_styles, $file_index ) {
$style_path = "{$name}/{$filename}{$suffix}.css";
$path = wp_normalize_path( BLOCKS_PATH . $style_path );

if ( ! in_array( $style_path, $files, true ) ) {
if ( ! isset( $file_index[ $style_path ] ) ) {
$wp_styles->add(
$style_handle,
false
);
return;
}

$path = wp_normalize_path( BLOCKS_PATH . $style_path );

$wp_styles->add( $style_handle, $blocks_url . $style_path );
$wp_styles->add_data( $style_handle, 'path', $path );

$rtl_file = "{$name}/{$filename}-rtl{$suffix}.css";
if ( is_rtl() && in_array( $rtl_file, $files, true ) ) {
if ( is_rtl() && isset( $file_index[ $rtl_file ] ) ) {
$wp_styles->add_data( $style_handle, 'rtl', 'replace' );
$wp_styles->add_data( $style_handle, 'suffix', $suffix );
$wp_styles->add_data( $style_handle, 'path', str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ) );
Expand Down
Loading