WP_Block_Metadata_Registry::get_metadata( string $file_or_folder ): array|null

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_folderstringrequired
The path to the file or folder containing the block.

Return

array|null The block metadata for the block, or null if not found.

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

VersionDescription
6.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.