Changeset 59132
- Timestamp:
- 09/30/2024 05:05:37 PM (2 months ago)
- Location:
- trunk
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r59124 r59132 377 377 378 378 /** 379 * Registers a block metadata collection. 380 * 381 * This function allows core and third-party plugins to register their block metadata 382 * collections in a centralized location. Registering collections can improve performance 383 * by avoiding multiple reads from the filesystem and parsing JSON. 384 * 385 * @since 6.7.0 386 * 387 * @param string $path The base path in which block files for the collection reside. 388 * @param string $manifest The path to the manifest file for the collection. 389 */ 390 function wp_register_block_metadata_collection( $path, $manifest ) { 391 WP_Block_Metadata_Registry::register_collection( $path, $manifest ); 392 } 393 394 /** 379 395 * Registers a block type from the metadata stored in the `block.json` file. 380 396 * … … 403 419 * Using a static variable ensures that the metadata is only read once per request. 404 420 */ 405 static $core_blocks_meta;406 if ( ! $core_blocks_meta ) {407 $core_blocks_meta = require ABSPATH . WPINC . '/blocks/blocks-json.php';408 }409 421 410 422 $metadata_file = ( ! str_ends_with( $file_or_folder, 'block.json' ) ) ? … … 412 424 $file_or_folder; 413 425 414 $is_core_block = str_starts_with( $file_or_folder, ABSPATH . WPINC ); 415 // If the block is not a core block, the metadata file must exist. 426 $is_core_block = str_starts_with( $file_or_folder, ABSPATH . WPINC ); 416 427 $metadata_file_exists = $is_core_block || file_exists( $metadata_file ); 417 if ( ! $metadata_file_exists && empty( $args['name'] ) ) { 418 return false; 419 } 420 421 // Try to get metadata from the static cache for core blocks. 422 $metadata = array(); 423 if ( $is_core_block ) { 424 $core_block_name = str_replace( ABSPATH . WPINC . '/blocks/', '', $file_or_folder ); 425 if ( ! empty( $core_blocks_meta[ $core_block_name ] ) ) { 426 $metadata = $core_blocks_meta[ $core_block_name ]; 427 } 428 } 429 430 // If metadata is not found in the static cache, read it from the file. 431 if ( $metadata_file_exists && empty( $metadata ) ) { 428 $registry_metadata = WP_Block_Metadata_Registry::get_metadata( $file_or_folder ); 429 430 if ( $registry_metadata ) { 431 $metadata = $registry_metadata; 432 } elseif ( $metadata_file_exists ) { 432 433 $metadata = wp_json_file_decode( $metadata_file, array( 'associative' => true ) ); 434 } else { 435 $metadata = array(); 433 436 } 434 437 -
trunk/src/wp-includes/blocks/index.php
r59117 r59132 161 161 } 162 162 add_action( 'init', 'register_core_block_types_from_metadata' ); 163 164 /** 165 * Registers the core block metadata collection. 166 * 167 * This function is hooked into the 'init' action with a priority of 9, 168 * ensuring that the core block metadata is registered before the regular 169 * block initialization that happens at priority 10. 170 * 171 * @since 6.7.0 172 */ 173 function wp_register_core_block_metadata_collection() { 174 wp_register_block_metadata_collection( 175 BLOCKS_PATH, 176 BLOCKS_PATH . 'blocks-json.php' 177 ); 178 } 179 add_action( 'init', 'wp_register_core_block_metadata_collection', 9 ); -
trunk/src/wp-settings.php
r59107 r59132 356 356 require ABSPATH . WPINC . '/class-wp-block.php'; 357 357 require ABSPATH . WPINC . '/class-wp-block-list.php'; 358 require ABSPATH . WPINC . '/class-wp-block-metadata-registry.php'; 358 359 require ABSPATH . WPINC . '/class-wp-block-parser-block.php'; 359 360 require ABSPATH . WPINC . '/class-wp-block-parser-frame.php';
Note: See TracChangeset
for help on using the changeset viewer.