From cdcbfd19f4ff3dc5368424cf03ada7c829d32e3c Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Mon, 20 Feb 2023 21:11:57 +0000 Subject: [PATCH] Editor: Fix 'wp-block-library-theme' style enqueue conditions. Fixes the conditions for when to enqueue the opinionated block styles (i.e. `'wp-block-library-theme'` stylesheet): * the theme adds `'wp-block-styles'` theme support; * and no editor styles are declared. This resolves an issue with themes that do not add the `'wp-block-styles'` theme support while not impacting themes that do. Follow-up to [53419], [52069], [50761], [44157]. Props mikachan, costdev, glendaviesnz, hellofromTonya, jffng, mamaduka, ndiego, poena, sannevndrmeulen, scruffian. Fixes #57561. git-svn-id: https://develop.svn.wordpress.org/trunk@55368 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/site-editor.php | 2 +- src/wp-includes/block-editor.php | 7 +++++-- src/wp-includes/script-loader.php | 10 ++++++++-- tests/phpunit/tests/dependencies/styles.php | 6 +++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index dd5211dc0b..9302c42389 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -120,7 +120,7 @@ wp_enqueue_style( 'wp-format-library' ); wp_enqueue_media(); if ( - current_theme_supports( 'wp-block-styles' ) || + current_theme_supports( 'wp-block-styles' ) && ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) ) { wp_enqueue_style( 'wp-block-library-theme' ); diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index acf7b5d550..b42c0c09f0 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -296,7 +296,7 @@ function get_legacy_widget_block_editor_settings() { * } */ function _wp_get_iframed_editor_assets() { - global $pagenow; + global $pagenow, $editor_styles; $script_handles = array( 'wp-polyfill', @@ -305,7 +305,10 @@ function _wp_get_iframed_editor_assets() { 'wp-edit-blocks', ); - if ( current_theme_supports( 'wp-block-styles' ) ) { + if ( + current_theme_supports( 'wp-block-styles' ) && + ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) + ) { $style_handles[] = 'wp-block-library-theme'; } diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 5216ff299a..acdfac640d 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -1635,8 +1635,14 @@ function wp_default_styles( $styles ) { $wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles'; } - if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) { - // Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken. + if ( + current_theme_supports( 'wp-block-styles' ) && + ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) + ) { + /* + * Include opinionated block styles if the theme supports block styles and + * no $editor_styles are declared, so the editor never appears broken. + */ $wp_edit_blocks_dependencies[] = 'wp-block-library-theme'; } diff --git a/tests/phpunit/tests/dependencies/styles.php b/tests/phpunit/tests/dependencies/styles.php index 34a9847f2f..0d2f8e664b 100644 --- a/tests/phpunit/tests/dependencies/styles.php +++ b/tests/phpunit/tests/dependencies/styles.php @@ -405,9 +405,9 @@ CSS; } /** - * Tests that visual block styles are enqueued in the editor even when there is not theme support for 'wp-block-styles'. + * Tests that visual block styles are not be enqueued in the editor when there is not theme support for 'wp-block-styles'. * - * Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. + * @ticket 57561 * * @covers ::wp_enqueue_style */ @@ -419,7 +419,7 @@ CSS; $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); wp_enqueue_style( 'wp-edit-blocks' ); - $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); + $this->assertFalse( wp_style_is( 'wp-block-library-theme' ), "The 'wp-block-library-theme' style should not be in the queue after enqueuing 'wp-edit-blocks'" ); } /**