Make WordPress Core

Changeset 51254


Ignore:
Timestamp:
06/29/2021 12:07:53 AM (3 years ago)
Author:
desrosj
Message:

Editor: Prevent block stylesheets from loading when they do not exist.

This fixes an issue where block stylesheets were being loaded even if they did not exist, causing 404 errors. The issue presented itself when the site was choosing to load block assets individually through the should_load_separate_core_block_assets filter hook.

This also fixes an issue where non-Core blocks would only be registered if they actually had asset files. This prevents developers from adding additional information to a style handle, such as inline styles through wp_add_inline_style().

Props walbo, jorbin, aristath, desrosj, hellofromTonya.
Fixes #53375.

File:
1 edited

Legend:

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

    r51221 r51254  
    152152    }
    153153
    154     $style_handle = generate_block_asset_handle( $metadata['name'], $field_name );
    155     $block_dir    = dirname( $metadata['file'] );
    156     $style_file   = realpath( "$block_dir/$style_path" );
    157     $version      = file_exists( $style_file ) ? filemtime( $style_file ) : false;
     154    $style_handle   = generate_block_asset_handle( $metadata['name'], $field_name );
     155    $block_dir      = dirname( $metadata['file'] );
     156    $style_file     = realpath( "$block_dir/$style_path" );
     157    $has_style_file = false !== $style_file;
     158    $version        = ! $is_core_block && $has_style_file ? filemtime( $style_file ) : false;
     159    $style_uri      = $has_style_file ? $style_uri : false;
    158160    $result       = wp_register_style(
    159161        $style_handle,
     
    165167        wp_style_add_data( $style_handle, 'rtl', 'replace' );
    166168    }
    167     if ( file_exists( $style_file ) ) {
     169    if ( $has_style_file ) {
    168170        wp_style_add_data( $style_handle, 'path', $style_file );
    169171    }
     
    222224            $metadata['style'] = "wp-block-$block_name";
    223225        }
    224         if ( ! isset( $metadata['editor_style'] ) ) {
    225             $metadata['editor_style'] = "wp-block-$block_name-editor";
     226        if ( ! isset( $metadata['editorStyle'] ) ) {
     227            $metadata['editorStyle'] = "wp-block-{$block_name}-editor";
    226228        }
    227229    }
Note: See TracChangeset for help on using the changeset viewer.