Changeset 54118 for trunk/src/wp-includes/global-styles-and-settings.php
- Timestamp:
- 09/10/2022 12:37:00 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/global-styles-and-settings.php
r52757 r54118 193 193 return $svgs; 194 194 } 195 196 /** 197 * Adds global style rules to the inline style for each block. 198 * 199 * @since 6.1.0 200 */ 201 function wp_add_global_styles_for_blocks() { 202 $tree = WP_Theme_JSON_Resolver::get_merged_data(); 203 $block_nodes = $tree->get_styles_block_nodes(); 204 foreach ( $block_nodes as $metadata ) { 205 $block_css = $tree->get_styles_for_block( $metadata ); 206 207 if ( isset( $metadata['name'] ) ) { 208 $block_name = str_replace( 'core/', '', $metadata['name'] ); 209 /* 210 * These block styles are added on block_render. 211 * This hooks inline CSS to them so that they are loaded conditionally 212 * based on whether or not the block is used on the page. 213 */ 214 wp_add_inline_style( 'wp-block-' . $block_name, $block_css ); 215 } 216 217 // The likes of block element styles from theme.json do not have $metadata['name'] set. 218 if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) { 219 $result = array_values( 220 array_filter( 221 $metadata['path'], 222 function ( $item ) { 223 if ( strpos( $item, 'core/' ) !== false ) { 224 return true; 225 } 226 return false; 227 } 228 ) 229 ); 230 if ( isset( $result[0] ) ) { 231 $block_name = str_replace( 'core/', '', $result[0] ); 232 wp_add_inline_style( 'wp-block-' . $block_name, $block_css ); 233 } 234 } 235 } 236 }
Note: See TracChangeset
for help on using the changeset viewer.