wp_allowed_block_metadata_collection_roots filter-hookWP 6.7.2

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.

Usage

add_filter( 'wp_allowed_block_metadata_collection_roots', 'wp_kama_allowed_block_metadata_collection_roots_filter' );

/**
 * Function for `wp_allowed_block_metadata_collection_roots` filter-hook.
 * 
 * @param string[] $collection_roots List of allowed metadata collection root paths.
 *
 * @return string[]
 */
function wp_kama_allowed_block_metadata_collection_roots_filter( $collection_roots ){

	// filter...
	return $collection_roots;
}
$collection_roots(string[])
List of allowed metadata collection root paths.

Changelog

Since 6.7.2 Introduced.

Where the hook is called

WP_Block_Metadata_Registry::register_collection()
wp_allowed_block_metadata_collection_roots
wp-includes/class-wp-block-metadata-registry.php 110
$collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $collection_roots );

Where the hook is used in WordPress

Usage not found.