diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 5fa7f1d6d0..aebb4b4065 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -373,6 +373,10 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { if ( ! isset( $metadata['style'] ) ) { $metadata['style'] = "wp-block-$block_name"; } + if ( current_theme_supports( 'wp-block-styles' ) && wp_should_load_separate_core_block_assets() ) { + $metadata['style'] = (array) $metadata['style']; + $metadata['style'][] = "wp-block-{$block_name}-theme"; + } if ( ! isset( $metadata['editorStyle'] ) ) { $metadata['editorStyle'] = "wp-block-{$block_name}-editor"; } diff --git a/wp-includes/blocks/index.php b/wp-includes/blocks/index.php index 51cf0c91e8..f9ffa411af 100644 --- a/wp-includes/blocks/index.php +++ b/wp-includes/blocks/index.php @@ -55,6 +55,29 @@ function register_core_block_style_handles() { $files = glob( __DIR__ . '/**/**.css' ); } + $register_style = static function( $name, $filename, $style_handle ) use ( $includes_path, $includes_url, $suffix, $wp_styles, $files ) { + $style_path = "blocks/{$name}/{$filename}{$suffix}.css"; + $path = $includes_path . $style_path; + + if ( ! in_array( $path, $files, true ) ) { + $wp_styles->add( + $style_handle, + false + ); + return; + } + + $wp_styles->add( $style_handle, $includes_url . $style_path ); + $wp_styles->add_data( $style_handle, 'path', $path ); + + $rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ); + if ( is_rtl() && in_array( $rtl_file, $files, true ) ) { + $wp_styles->add_data( $style_handle, 'rtl', 'replace' ); + $wp_styles->add_data( $style_handle, 'suffix', $suffix ); + $wp_styles->add_data( $style_handle, 'path', $rtl_file ); + } + }; + foreach ( $core_blocks_meta as $name => $schema ) { /** This filter is documented in wp-includes/blocks.php */ $schema = apply_filters( 'block_type_metadata', $schema ); @@ -67,32 +90,15 @@ function register_core_block_style_handles() { $schema['editorStyle'] = "wp-block-{$name}-editor"; } + // Register block theme styles. + $register_style( $name, 'theme', "wp-block-{$name}-theme" ); + foreach ( $style_fields as $style_field => $filename ) { $style_handle = $schema[ $style_field ]; if ( is_array( $style_handle ) ) { continue; } - - $style_path = "blocks/{$name}/{$filename}{$suffix}.css"; - $path = $includes_path . $style_path; - - if ( ! in_array( $path, $files, true ) ) { - $wp_styles->add( - $style_handle, - false - ); - continue; - } - - $wp_styles->add( $style_handle, $includes_url . $style_path ); - $wp_styles->add_data( $style_handle, 'path', $path ); - - $rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ); - if ( is_rtl() && in_array( $rtl_file, $files, true ) ) { - $wp_styles->add_data( $style_handle, 'rtl', 'replace' ); - $wp_styles->add_data( $style_handle, 'suffix', $suffix ); - $wp_styles->add_data( $style_handle, 'path', $rtl_file ); - } + $register_style( $name, $filename, $style_handle ); } } } diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 8d9b54eb43..b6414350b7 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -2372,20 +2372,8 @@ function wp_common_block_scripts_and_styles() { wp_enqueue_style( 'wp-block-library' ); - if ( current_theme_supports( 'wp-block-styles' ) ) { - if ( wp_should_load_separate_core_block_assets() ) { - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'css' : 'min.css'; - $files = glob( __DIR__ . "/blocks/**/theme.$suffix" ); - foreach ( $files as $path ) { - $block_name = basename( dirname( $path ) ); - if ( is_rtl() && file_exists( __DIR__ . "/blocks/$block_name/theme-rtl.$suffix" ) ) { - $path = __DIR__ . "/blocks/$block_name/theme-rtl.$suffix"; - } - wp_add_inline_style( "wp-block-{$block_name}", file_get_contents( $path ) ); - } - } else { - wp_enqueue_style( 'wp-block-library-theme' ); - } + if ( current_theme_supports( 'wp-block-styles' ) && ! wp_should_load_separate_core_block_assets() ) { + wp_enqueue_style( 'wp-block-library-theme' ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index ed631625f4..2bd99e4068 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-56063'; +$wp_version = '6.3-alpha-56064'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.