Changeset 57546
- Timestamp:
- 02/07/2024 04:35:34 AM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/global-styles-and-settings.php
r57309 r57546 299 299 * 300 300 * @since 6.1.0 301 * 302 * @global WP_Styles $wp_styles 301 303 */ 302 304 function wp_add_global_styles_for_blocks() { 305 global $wp_styles; 306 303 307 $tree = WP_Theme_JSON_Resolver::get_merged_data(); 304 308 $block_nodes = $tree->get_styles_block_nodes(); … … 312 316 313 317 $stylesheet_handle = 'global-styles'; 318 319 /* 320 * When `wp_should_load_separate_core_block_assets()` is true, block styles are 321 * enqueued for each block on the page in class WP_Block's render function. 322 * This means there will be a handle in the styles queue for each of those blocks. 323 * Block-specific global styles should be attached to the global-styles handle, but 324 * only for blocks on the page, thus we check if the block's handle is in the queue 325 * before adding the inline style. 326 * This conditional loading only applies to core blocks. 327 */ 314 328 if ( isset( $metadata['name'] ) ) { 315 /*316 * These block styles are added on block_render.317 * This hooks inline CSS to them so that they are loaded conditionally318 * based on whether or not the block is used on the page.319 */320 329 if ( str_starts_with( $metadata['name'], 'core/' ) ) { 321 $block_name = str_replace( 'core/', '', $metadata['name'] ); 322 $stylesheet_handle = 'wp-block-' . $block_name; 330 $block_name = str_replace( 'core/', '', $metadata['name'] ); 331 $block_handle = 'wp-block-' . $block_name; 332 if ( in_array( $block_handle, $wp_styles->queue ) ) { 333 wp_add_inline_style( $stylesheet_handle, $block_css ); 334 } 335 } else { 336 wp_add_inline_style( $stylesheet_handle, $block_css ); 323 337 } 324 wp_add_inline_style( $stylesheet_handle, $block_css );325 338 } 326 339 … … 330 343 if ( $block_name ) { 331 344 if ( str_starts_with( $block_name, 'core/' ) ) { 332 $block_name = str_replace( 'core/', '', $block_name ); 333 $stylesheet_handle = 'wp-block-' . $block_name; 345 $block_name = str_replace( 'core/', '', $block_name ); 346 $block_handle = 'wp-block-' . $block_name; 347 if ( in_array( $block_handle, $wp_styles->queue ) ) { 348 wp_add_inline_style( $stylesheet_handle, $block_css ); 349 } 350 } else { 351 wp_add_inline_style( $stylesheet_handle, $block_css ); 334 352 } 335 wp_add_inline_style( $stylesheet_handle, $block_css );336 353 } 337 354 }
Note: See TracChangeset
for help on using the changeset viewer.