Changeset 59256 for trunk/src/wp-includes/global-styles-and-settings.php
- Timestamp:
- 10/18/2024 09:53:45 PM (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/global-styles-and-settings.php
r58797 r59256 258 258 $tree = WP_Theme_JSON_Resolver::resolve_theme_file_uris( $tree ); 259 259 $block_nodes = $tree->get_styles_block_nodes(); 260 261 $can_use_cached = ! wp_is_development_mode( 'theme' ); 262 $update_cache = false; 263 264 if ( $can_use_cached ) { 265 // Hash the merged WP_Theme_JSON data to bust cache on settings or styles change. 266 $cache_hash = md5( wp_json_encode( $tree->get_raw_data() ) ); 267 $cache_key = 'wp_styles_for_blocks'; 268 $cached = get_transient( $cache_key ); 269 270 // Reset the cached data if there is no value or if the hash has changed. 271 if ( ! is_array( $cached ) || $cached['hash'] !== $cache_hash ) { 272 $cached = array( 273 'hash' => $cache_hash, 274 'blocks' => array(), 275 ); 276 277 // Update the cache if the hash has changed. 278 $update_cache = true; 279 } 280 } 281 260 282 foreach ( $block_nodes as $metadata ) { 261 $block_css = $tree->get_styles_for_block( $metadata ); 283 284 if ( $can_use_cached ) { 285 // Use the block name as the key for cached CSS data. Otherwise, use a hash of the metadata. 286 $cache_node_key = isset( $metadata['name'] ) ? $metadata['name'] : md5( wp_json_encode( $metadata ) ); 287 288 if ( isset( $cached['blocks'][ $cache_node_key ] ) ) { 289 $block_css = $cached['blocks'][ $cache_node_key ]; 290 } else { 291 $block_css = $tree->get_styles_for_block( $metadata ); 292 $cached['blocks'][ $cache_node_key ] = $block_css; 293 294 // Update the cache if the cache contents have changed. 295 $update_cache = true; 296 } 297 } else { 298 $block_css = $tree->get_styles_for_block( $metadata ); 299 } 262 300 263 301 if ( ! wp_should_load_separate_core_block_assets() ) { … … 305 343 } 306 344 } 345 346 if ( $update_cache ) { 347 set_transient( $cache_key, $cached ); 348 } 307 349 } 308 350
Note: See TracChangeset
for help on using the changeset viewer.