Make WordPress Core

Changeset 55368


Ignore:
Timestamp:
02/20/2023 09:11:57 PM (2 years ago)
Author:
hellofromTonya
Message:

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.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/site-editor.php

    r55338 r55368  
    121121
    122122if (
    123     current_theme_supports( 'wp-block-styles' ) ||
     123    current_theme_supports( 'wp-block-styles' ) &&
    124124    ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
    125125) {
  • trunk/src/wp-includes/block-editor.php

    r55192 r55368  
    297297 */
    298298function _wp_get_iframed_editor_assets() {
    299     global $pagenow;
     299    global $pagenow, $editor_styles;
    300300
    301301    $script_handles = array(
     
    306306    );
    307307
    308     if ( current_theme_supports( 'wp-block-styles' ) ) {
     308    if (
     309        current_theme_supports( 'wp-block-styles' ) &&
     310        ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
     311    ) {
    309312        $style_handles[] = 'wp-block-library-theme';
    310313    }
  • trunk/src/wp-includes/script-loader.php

    r55314 r55368  
    16361636    }
    16371637
    1638     if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) {
    1639         // Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken.
     1638    if (
     1639        current_theme_supports( 'wp-block-styles' ) &&
     1640        ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
     1641    ) {
     1642        /*
     1643         * Include opinionated block styles if the theme supports block styles and
     1644         * no $editor_styles are declared, so the editor never appears broken.
     1645         */
    16401646        $wp_edit_blocks_dependencies[] = 'wp-block-library-theme';
    16411647    }
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r54348 r55368  
    406406
    407407    /**
    408      * Tests that visual block styles are enqueued in the editor even when there is not theme support for 'wp-block-styles'.
    409      *
    410      * Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor.
     408     * Tests that visual block styles are not be enqueued in the editor when there is not theme support for 'wp-block-styles'.
     409     *
     410     * @ticket 57561
    411411     *
    412412     * @covers ::wp_enqueue_style
     
    420420        $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) );
    421421        wp_enqueue_style( 'wp-edit-blocks' );
    422         $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) );
     422        $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'" );
    423423    }
    424424
Note: See TracChangeset for help on using the changeset viewer.