Title: WP_Block_Metadata_Registry::register_collection
Published: November 13, 2024
Last modified: August 20, 2026

---

# WP_Block_Metadata_Registry::register_collection( string $path, string $manifest ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#changelog)

Registers a block metadata collection.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#description)󠁿

This method allows registering a collection of block metadata from a single manifest
file, improving performance for large sets of blocks.

The manifest file should be a PHP file that returns an associative array, where 
the keys are the block identifiers (without their namespace) and the values are 
the corresponding block metadata arrays. The block identifiers must match the parent
directory name for the respective `block.json` file.

Example manifest file structure:

    ```php
    return array(
        'example-block' => array(
            'title' => 'Example Block',
            'category' => 'widgets',
            'icon' => 'smiley',
            // ... other block metadata
        ),
        'another-block' => array(
            'title' => 'Another Block',
            'category' => 'formatting',
            'icon' => 'star-filled',
            // ... other block metadata
        ),
        // ... more block metadata entries
    );
    ```

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#parameters)󠁿

 `$path`stringrequired

The absolute base path for the collection ( e.g., WP_PLUGIN_DIR . `'/my-plugin/blocks/'`).

`$manifest`stringrequired

The absolute path to the manifest file containing the metadata collection.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#return)󠁿

 bool True if the collection was registered successfully, false otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#source)󠁿

    ```php
    public static function register_collection( $path, $manifest ) {
    	$path = rtrim( wp_normalize_path( $path ), '/' );

    	$collection_roots = self::get_default_collection_roots();

    	/**
    	 * Filters the root directory paths for block metadata collections.
    	 *
    	 * Any block metadata collection that is registered must not use any of these paths, or any parent directory
    	 * path of them. Most commonly, block metadata collections should reside within one of these paths, though in
    	 * some scenarios they may also reside in entirely different directories (e.g. in case of symlinked plugins).
    	 *
    	 * Example:
    	 * * It is allowed to register a collection with path `WP_PLUGIN_DIR . '/my-plugin'`.
    	 * * It is not allowed to register a collection with path `WP_PLUGIN_DIR`.
    	 * * It is not allowed to register a collection with path `dirname( WP_PLUGIN_DIR )`.
    	 *
    	 * The default list encompasses the `wp-includes` directory, as well as the root directories for plugins,
    	 * must-use plugins, and themes. This filter can be used to expand the list, e.g. to custom directories that
    	 * contain symlinked plugins, so that these root directories cannot be used themselves for a block metadata
    	 * collection either.
    	 *
    	 * @since 6.7.2
    	 *
    	 * @param string[] $collection_roots List of allowed metadata collection root paths.
    	 */
    	$collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $collection_roots );

    	$collection_roots = array_unique(
    		array_map(
    			static function ( $allowed_root ) {
    				return rtrim( wp_normalize_path( $allowed_root ), '/' );
    			},
    			$collection_roots
    		)
    	);

    	// Check if the path is valid:
    	if ( ! self::is_valid_collection_path( $path, $collection_roots ) ) {
    		_doing_it_wrong(
    			__METHOD__,
    			sprintf(
    				/* translators: %s: list of allowed collection roots */
    				__( 'Block metadata collections cannot be registered as one of the following directories or their parent directories: %s' ),
    				esc_html( implode( wp_get_list_item_separator(), $collection_roots ) )
    			),
    			'6.7.2'
    		);
    		return false;
    	}

    	if ( ! file_exists( $manifest ) ) {
    		_doing_it_wrong(
    			__METHOD__,
    			__( 'The specified manifest file does not exist.' ),
    			'6.7.0'
    		);
    		return false;
    	}

    	self::$collections[ $path ] = array(
    		'manifest' => $manifest,
    		'metadata' => null,
    	);

    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-metadata-registry.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-block-metadata-registry.php#L84)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-block-metadata-registry.php#L84-L150)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_allowed_block_metadata_collection_roots’, string[] $collection_roots )](https://developer.wordpress.org/reference/hooks/wp_allowed_block_metadata_collection_roots/)

Filters the root directory paths for block metadata collections.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Block_Metadata_Registry::get_default_collection_roots()](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/get_default_collection_roots/)`wp-includes/class-wp-block-metadata-registry.php` |

Gets the default collection root directory paths.

  | 
| [WP_Block_Metadata_Registry::is_valid_collection_path()](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/is_valid_collection_path/)`wp-includes/class-wp-block-metadata-registry.php` |

Checks whether the given block metadata collection path is valid against the list of collection roots.

  | 
| [wp_get_list_item_separator()](https://developer.wordpress.org/reference/functions/wp_get_list_item_separator/)`wp-includes/l10n.php` |

Retrieves the list item separator based on the locale.

  | 
| [wp_normalize_path()](https://developer.wordpress.org/reference/functions/wp_normalize_path/)`wp-includes/functions.php` |

Normalizes a filesystem path.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [_doing_it_wrong()](https://developer.wordpress.org/reference/functions/_doing_it_wrong/)`wp-includes/functions.php` |

Marks something as being incorrectly called.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 4 more](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#)

| Used by | Description | 
| [wp_register_block_metadata_collection()](https://developer.wordpress.org/reference/functions/wp_register_block_metadata_collection/)`wp-includes/blocks.php` |

Registers a block metadata collection.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/register_collection/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.7.0](https://developer.wordpress.org/reference/since/6.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_block_metadata_registry%2Fregister_collection%2F)
before being able to contribute a note or feedback.