diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:57:26 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:57:26 +0000 |
commit | 30883c26bdceb9eaf32c8d4a1b0c1bce223b5226 (patch) | |
tree | 39a02e2aeb21ab5b7923c6f5757d66d55b708912 /wp-includes/global-styles-and-settings.php | |
parent | Adding upstream version 6.4.3+dfsg1. (diff) | |
download | wordpress-30883c26bdceb9eaf32c8d4a1b0c1bce223b5226.tar.xz wordpress-30883c26bdceb9eaf32c8d4a1b0c1bce223b5226.zip |
Adding upstream version 6.5+dfsg1.upstream/6.5+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/global-styles-and-settings.php')
-rw-r--r-- | wp-includes/global-styles-and-settings.php | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/wp-includes/global-styles-and-settings.php b/wp-includes/global-styles-and-settings.php index 1258f1f..fae7ae6 100644 --- a/wp-includes/global-styles-and-settings.php +++ b/wp-includes/global-styles-and-settings.php @@ -54,7 +54,7 @@ function wp_get_global_settings( $path = array(), $context = array() ) { * is always fresh from the potential modifications done via hooks * that can use dynamic data (modify the stylesheet depending on some option, * settings depending on user permissions, etc.). - * See some of the existing hooks to modify theme.json behaviour: + * See some of the existing hooks to modify theme.json behavior: * https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/ * * A different alternative considered was to invalidate the cache upon certain @@ -222,7 +222,13 @@ function wp_get_global_stylesheet( $types = array() ) { * @see wp_add_global_styles_for_blocks */ $origins = array( 'default', 'theme', 'custom' ); - if ( ! $supports_theme_json ) { + /* + * If the theme doesn't have theme.json but supports both appearance tools and color palette, + * the 'theme' origin should be included so color palette presets are also output. + */ + if ( ! $supports_theme_json && ( current_theme_supports( 'appearance-tools' ) || current_theme_supports( 'border' ) ) && current_theme_supports( 'editor-color-palette' ) ) { + $origins = array( 'default', 'theme' ); + } elseif ( ! $supports_theme_json ) { $origins = array( 'default' ); } $styles_rest = $tree->get_stylesheet( $types, $origins ); @@ -292,8 +298,12 @@ function wp_get_global_styles_custom_css() { * Adds global style rules to the inline style for each block. * * @since 6.1.0 + * + * @global WP_Styles $wp_styles */ function wp_add_global_styles_for_blocks() { + global $wp_styles; + $tree = WP_Theme_JSON_Resolver::get_merged_data(); $block_nodes = $tree->get_styles_block_nodes(); foreach ( $block_nodes as $metadata ) { @@ -305,17 +315,26 @@ function wp_add_global_styles_for_blocks() { } $stylesheet_handle = 'global-styles'; + + /* + * When `wp_should_load_separate_core_block_assets()` is true, block styles are + * enqueued for each block on the page in class WP_Block's render function. + * 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'] ) ) { - /* - * These block styles are added on block_render. - * This hooks inline CSS to them so that they are loaded conditionally - * based on whether or not the block is used on the page. - */ if ( str_starts_with( $metadata['name'], 'core/' ) ) { - $block_name = str_replace( 'core/', '', $metadata['name'] ); - $stylesheet_handle = 'wp-block-' . $block_name; + $block_name = str_replace( 'core/', '', $metadata['name'] ); + $block_handle = 'wp-block-' . $block_name; + if ( in_array( $block_handle, $wp_styles->queue ) ) { + wp_add_inline_style( $stylesheet_handle, $block_css ); + } + } else { + wp_add_inline_style( $stylesheet_handle, $block_css ); } - wp_add_inline_style( $stylesheet_handle, $block_css ); } // The likes of block element styles from theme.json do not have $metadata['name'] set. @@ -323,10 +342,14 @@ function wp_add_global_styles_for_blocks() { $block_name = wp_get_block_name_from_theme_json_path( $metadata['path'] ); if ( $block_name ) { if ( str_starts_with( $block_name, 'core/' ) ) { - $block_name = str_replace( 'core/', '', $block_name ); - $stylesheet_handle = 'wp-block-' . $block_name; + $block_name = str_replace( 'core/', '', $block_name ); + $block_handle = 'wp-block-' . $block_name; + if ( in_array( $block_handle, $wp_styles->queue ) ) { + wp_add_inline_style( $stylesheet_handle, $block_css ); + } + } else { + wp_add_inline_style( $stylesheet_handle, $block_css ); } - wp_add_inline_style( $stylesheet_handle, $block_css ); } } } |