Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update conditional logic for editor_styles #3916

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static function( $classes ) {
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' );
Expand Down
7 changes: 5 additions & 2 deletions src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function get_legacy_widget_block_editor_settings() {
* }
*/
function _wp_get_iframed_editor_assets() {
global $pagenow;
global $pagenow, $editor_styles;

$script_handles = array();
$style_handles = array(
Expand All @@ -323,7 +323,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';
}

Expand Down
10 changes: 8 additions & 2 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -1624,8 +1624,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';
}

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/dependencies/styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ public function data_styles_with_media() {
}

/**
* 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
*/
Expand All @@ -419,7 +419,7 @@ public function test_block_styles_for_editing_without_theme_support() {

$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'" );
}

/**
Expand Down