Retrieves block metadata for a given block within a specific collection.
Description
This method uses the registered collections to efficiently lookup block metadata without reading individual block.json
files.
Parameters
$file_or_folder
stringrequired- The path to the file or folder containing the block.
Source
public static function get_metadata( $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;
}
Changelog
Version | Description |
---|---|
6.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.