Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions src/wp-includes/blocks/index.php
Comment thread
josephscott marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,31 @@ 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. The closure below only needs to know whether a given
* path is present, and each path is always a string, so an isset() lookup against the
* keys of this index replaces an in_array() scan over the entire list of files.
*/
$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
Loading