From 516bc482bd2b1ffcbb07455c3b2860ab4c9a6cb0 Mon Sep 17 00:00:00 2001 From: desrosj Date: Tue, 29 Jun 2021 00:08:57 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@51254 git-svn-id: http://core.svn.wordpress.org/trunk@50863 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 16 +++++++++------- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index dc9f9110c5..825b864c43 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -151,10 +151,12 @@ function register_block_style_handle( $metadata, $field_name ) { $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" ); } - $style_handle = generate_block_asset_handle( $metadata['name'], $field_name ); - $block_dir = dirname( $metadata['file'] ); - $style_file = realpath( "$block_dir/$style_path" ); - $version = file_exists( $style_file ) ? filemtime( $style_file ) : false; + $style_handle = generate_block_asset_handle( $metadata['name'], $field_name ); + $block_dir = dirname( $metadata['file'] ); + $style_file = realpath( "$block_dir/$style_path" ); + $has_style_file = false !== $style_file; + $version = ! $is_core_block && $has_style_file ? filemtime( $style_file ) : false; + $style_uri = $has_style_file ? $style_uri : false; $result = wp_register_style( $style_handle, $style_uri, @@ -164,7 +166,7 @@ function register_block_style_handle( $metadata, $field_name ) { if ( file_exists( str_replace( '.css', '-rtl.css', $style_file ) ) ) { wp_style_add_data( $style_handle, 'rtl', 'replace' ); } - if ( file_exists( $style_file ) ) { + if ( $has_style_file ) { wp_style_add_data( $style_handle, 'path', $style_file ); } @@ -221,8 +223,8 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { if ( ! isset( $metadata['style'] ) ) { $metadata['style'] = "wp-block-$block_name"; } - if ( ! isset( $metadata['editor_style'] ) ) { - $metadata['editor_style'] = "wp-block-$block_name-editor"; + if ( ! isset( $metadata['editorStyle'] ) ) { + $metadata['editorStyle'] = "wp-block-{$block_name}-editor"; } } diff --git a/wp-includes/version.php b/wp-includes/version.php index c7969df606..a3d06382dd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-beta4-51253'; +$wp_version = '5.8-beta4-51254'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.