Filter hook 'wp_allowed_block_metadata_collection_roots'

in WP Core File wp-includes/class-wp-block-metadata-registry.php at line 110

View Source

wp_allowed_block_metadata_collection_roots

Filter Hook
Description
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.

Hook Information

File Location wp-includes/class-wp-block-metadata-registry.php View on GitHub
Hook Type Filter
Line Number 110

Hook Parameters

Type Name Description
string[] $collection_roots List of allowed metadata collection root paths.

Usage Examples

Basic Usage
<?php
// Hook into wp_allowed_block_metadata_collection_roots
add_filter('wp_allowed_block_metadata_collection_roots', 'my_custom_filter', 10, 1);

function my_custom_filter($collection_roots) {
    // Your custom filtering logic here
    return $collection_roots;
}

Source Code Context

wp-includes/class-wp-block-metadata-registry.php:110 - How this hook is used in WordPress core
<?php
 105  		 *
 106  		 * @since 6.7.2
 107  		 *
 108  		 * @param string[] $collection_roots List of allowed metadata collection root paths.
 109  		 */
 110  		$collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $collection_roots );
 111  
 112  		$collection_roots = array_unique(
 113  			array_map(
 114  				static function ( $allowed_root ) {
 115  					return rtrim( wp_normalize_path( $allowed_root ), '/' );

PHP Documentation

<?php
/**
		 * 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.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/class-wp-block-metadata-registry.php
Related Hooks

Related hooks will be displayed here in future updates.