wp_allowed_block_metadata_collection_roots
概述
wp_allowed_block_metadata_collection_roots 是一个 WordPress 过滤器,用于定义允许的块元数据集合根目录路径。它确保注册的集合路径不冲突于这些根路径或其父目录,常用于管理插件或主题中的块元数据。
关键要点
- 过滤器用于控制块元数据集合的根目录路径,防止注册冲突。
- 默认路径包括 wp-includes、插件、必须使用插件和主题的根目录。
- 可以通过此过滤器扩展路径列表,例如添加包含符号链接插件的自定义目录。
- 注册集合时,路径不能是这些根路径或其父目录,但通常应位于这些路径内。
代码示例
$collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $collection_roots );注意事项
- 允许注册路径如 WP_PLUGIN_DIR . '/my-plugin',但不允许直接使用 WP_PLUGIN_DIR 或其父目录。
- 此过滤器在 WP_Block_Metadata_Registry::register_collection() 中使用,确保集合注册的安全性。
- 从 WordPress 6.7.2 版本引入。
Filters the root directory paths for block metadata collections.
Description
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.
Parameters
$collection_rootsstring[]-
List of allowed metadata collection root paths.
Source
$collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $collection_roots );
Changelog
| Version | Description |
|---|---|
| 6.7.2 | Introduced. |