Make WordPress Core

Changeset 54703


Ignore:
Timestamp:
10/27/2022 03:39:20 PM (18 months ago)
Author:
davidbaumwald
Message:

Editor: Ensure global styles are rendered for third-party blocks.

This change ensures custom styles for all third-party blocks are rendered on the front end if assets are set to be loaded on a per-block basis. Additionally, this change includes new unit tests to help prevent a similar bug in the future.

Props scruffian, aristath, poena, wildworks, ajlende, andraganescu, ndiego, gigitux, cbravobernal, ramonopoly, andrewserong, oandregal, hellofromTonya, bernhard-reiter.
Fixes #56915.

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpcs.xml.dist

    r54269 r54703  
    245245                <element value="WP_Test_Adjacent_Image_Link_TestCase"/>
    246246                <element value="WP_Tests_Image_Resize_UnitTestCase"/>
     247                <element value="WP_Theme_UnitTestCase"/>
    247248
    248249                <!-- Mock classes. -->
  • trunk/src/wp-includes/global-styles-and-settings.php

    r54412 r54703  
    219219        }
    220220
     221        $stylesheet_handle = 'global-styles';
    221222        if ( isset( $metadata['name'] ) ) {
    222             $block_name = str_replace( 'core/', '', $metadata['name'] );
    223223            /*
    224224             * These block styles are added on block_render.
     
    226226             * based on whether or not the block is used on the page.
    227227             */
    228             wp_add_inline_style( 'wp-block-' . $block_name, $block_css );
     228            if ( str_starts_with( $metadata['name'], 'core/' ) ) {
     229                $block_name        = str_replace( 'core/', '', $metadata['name'] );
     230                $stylesheet_handle = 'wp-block-' . $block_name;
     231            }
     232            wp_add_inline_style( $stylesheet_handle, $block_css );
    229233        }
    230234
     
    243247            );
    244248            if ( isset( $result[0] ) ) {
    245                 $block_name = str_replace( 'core/', '', $result[0] );
    246                 wp_add_inline_style( 'wp-block-' . $block_name, $block_css );
     249                if ( str_starts_with( $result[0], 'core/' ) ) {
     250                    $block_name        = str_replace( 'core/', '', $result[0] );
     251                    $stylesheet_handle = 'wp-block-' . $block_name;
     252                }
     253                wp_add_inline_style( $stylesheet_handle, $block_css );
    247254            }
    248255        }
  • trunk/tests/phpunit/data/themedir1/block-theme/theme.json

    r54443 r54703  
    7070                    "duotone": "var(--wp--preset--duotone--custom-duotone)"
    7171                }
     72            },
     73            "my/third-party-block": {
     74                "color": {
     75                    "background": "hotpink"
     76                }
    7277            }
    7378        },
Note: See TracChangeset for help on using the changeset viewer.