mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-24 21:32:51 +02:00
Script Loader: always output core block global styles after base global styles.
Changes the output of core block global styles when `should_load_separate_core_block_assets` is true so they are appended to base global styles instead of block-library styles. Props isabel_brison, oandregal, azaozz, ajlende. Fixes #60280. Built from https://develop.svn.wordpress.org/trunk@57546 git-svn-id: http://core.svn.wordpress.org/trunk@57047 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c60fc98b33
commit
e692b93540
@ -298,8 +298,12 @@ function wp_get_global_styles_custom_css() {
|
|||||||
* Adds global style rules to the inline style for each block.
|
* Adds global style rules to the inline style for each block.
|
||||||
*
|
*
|
||||||
* @since 6.1.0
|
* @since 6.1.0
|
||||||
|
*
|
||||||
|
* @global WP_Styles $wp_styles
|
||||||
*/
|
*/
|
||||||
function wp_add_global_styles_for_blocks() {
|
function wp_add_global_styles_for_blocks() {
|
||||||
|
global $wp_styles;
|
||||||
|
|
||||||
$tree = WP_Theme_JSON_Resolver::get_merged_data();
|
$tree = WP_Theme_JSON_Resolver::get_merged_data();
|
||||||
$block_nodes = $tree->get_styles_block_nodes();
|
$block_nodes = $tree->get_styles_block_nodes();
|
||||||
foreach ( $block_nodes as $metadata ) {
|
foreach ( $block_nodes as $metadata ) {
|
||||||
@ -311,18 +315,27 @@ function wp_add_global_styles_for_blocks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$stylesheet_handle = 'global-styles';
|
$stylesheet_handle = 'global-styles';
|
||||||
if ( isset( $metadata['name'] ) ) {
|
|
||||||
/*
|
/*
|
||||||
* These block styles are added on block_render.
|
* When `wp_should_load_separate_core_block_assets()` is true, block styles are
|
||||||
* This hooks inline CSS to them so that they are loaded conditionally
|
* enqueued for each block on the page in class WP_Block's render function.
|
||||||
* based on whether or not the block is used on the page.
|
* This means there will be a handle in the styles queue for each of those blocks.
|
||||||
|
* Block-specific global styles should be attached to the global-styles handle, but
|
||||||
|
* only for blocks on the page, thus we check if the block's handle is in the queue
|
||||||
|
* before adding the inline style.
|
||||||
|
* This conditional loading only applies to core blocks.
|
||||||
*/
|
*/
|
||||||
|
if ( isset( $metadata['name'] ) ) {
|
||||||
if ( str_starts_with( $metadata['name'], 'core/' ) ) {
|
if ( str_starts_with( $metadata['name'], 'core/' ) ) {
|
||||||
$block_name = str_replace( 'core/', '', $metadata['name'] );
|
$block_name = str_replace( 'core/', '', $metadata['name'] );
|
||||||
$stylesheet_handle = 'wp-block-' . $block_name;
|
$block_handle = 'wp-block-' . $block_name;
|
||||||
}
|
if ( in_array( $block_handle, $wp_styles->queue ) ) {
|
||||||
wp_add_inline_style( $stylesheet_handle, $block_css );
|
wp_add_inline_style( $stylesheet_handle, $block_css );
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
wp_add_inline_style( $stylesheet_handle, $block_css );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The likes of block element styles from theme.json do not have $metadata['name'] set.
|
// The likes of block element styles from theme.json do not have $metadata['name'] set.
|
||||||
if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) {
|
if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) {
|
||||||
@ -330,10 +343,14 @@ function wp_add_global_styles_for_blocks() {
|
|||||||
if ( $block_name ) {
|
if ( $block_name ) {
|
||||||
if ( str_starts_with( $block_name, 'core/' ) ) {
|
if ( str_starts_with( $block_name, 'core/' ) ) {
|
||||||
$block_name = str_replace( 'core/', '', $block_name );
|
$block_name = str_replace( 'core/', '', $block_name );
|
||||||
$stylesheet_handle = 'wp-block-' . $block_name;
|
$block_handle = 'wp-block-' . $block_name;
|
||||||
}
|
if ( in_array( $block_handle, $wp_styles->queue ) ) {
|
||||||
wp_add_inline_style( $stylesheet_handle, $block_css );
|
wp_add_inline_style( $stylesheet_handle, $block_css );
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
wp_add_inline_style( $stylesheet_handle, $block_css );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.5-alpha-57545';
|
$wp_version = '6.5-alpha-57546';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user