Make WordPress Core


Ignore:
Timestamp:
10/27/2022 03:39:20 PM (2 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.