WP_Block_Metadata_Registry::get_metadata
Retrieves block metadata for a given block within a specific collection.
This method uses the registered collections to efficiently lookup block metadata without reading individual block.json files.
Method of the class: WP_Block_Metadata_Registry{}
No Hooks.
Returns
Array|null
. The block metadata for the block, or null if not found.
Usage
$result = WP_Block_Metadata_Registry::get_metadata( $file_or_folder );
- $file_or_folder(string) (required)
- The path to the file or folder containing the block.
Changelog
Since 6.7.0 | Introduced. |
WP_Block_Metadata_Registry::get_metadata() WP Block Metadata Registry::get metadata code WP 6.8.1
public static function get_metadata( $file_or_folder ) { $file_or_folder = wp_normalize_path( $file_or_folder ); $path = self::find_collection_path( $file_or_folder ); if ( ! $path ) { return null; } $collection = &self::$collections[ $path ]; if ( null === $collection['metadata'] ) { // Load the manifest file if not already loaded $collection['metadata'] = require $collection['manifest']; } // Get the block name from the path. $block_name = self::default_identifier_callback( $file_or_folder ); return isset( $collection['metadata'][ $block_name ] ) ? $collection['metadata'][ $block_name ] : null; }