diff --git a/lib/blocks.php b/lib/blocks.php index 572edf576b1cf..eed9142db436a 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -269,23 +269,12 @@ function gutenberg_register_core_block_assets( $block_name ) { wp_register_style( "wp-block-{$block_name}", false, array() ); } - // If the current theme supports wp-block-styles, dequeue the full stylesheet - // and instead attach each block's theme-styles to their block styles stylesheet. + /* + * If the current theme supports wp-block-styles, dequeue the core styles + * and enqueue the plugin ones instead. + */ if ( current_theme_supports( 'wp-block-styles' ) ) { - // Dequeue the full stylesheet. - // Make sure this only runs once, it doesn't need to run for every block. - static $stylesheet_removed; - if ( ! $stylesheet_removed ) { - add_action( - 'wp_enqueue_scripts', - static function () { - wp_dequeue_style( 'wp-block-library-theme' ); - } - ); - $stylesheet_removed = true; - } - // Get the path to the block's stylesheet. $theme_style_path = is_rtl() ? "build/block-library/blocks/$block_name/theme-rtl.css" @@ -293,23 +282,14 @@ static function () { // If the file exists, enqueue it. if ( file_exists( gutenberg_dir_path() . $theme_style_path ) ) { - - if ( file_exists( $stylesheet_path ) ) { - // If there is a main stylesheet for this block, append the theme styles to main styles. - wp_add_inline_style( - "wp-block-{$block_name}", - file_get_contents( gutenberg_dir_path() . $theme_style_path ) - ); - } else { - // If there is no main stylesheet for this block, register theme style. - wp_register_style( - "wp-block-{$block_name}", - gutenberg_url( $theme_style_path ), - array(), - $default_version - ); - wp_style_add_data( "wp-block-{$block_name}", 'path', gutenberg_dir_path() . $theme_style_path ); - } + wp_deregister_style( "wp-block-{$block_name}-theme" ); + wp_register_style( + "wp-block-{$block_name}-theme", + gutenberg_url( $theme_style_path ), + array(), + $default_version + ); + wp_style_add_data( "wp-block-{$block_name}-theme", 'path', gutenberg_dir_path() . $theme_style_path ); } }