[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Block Metadata Registry
File Size: | 273 lines (8 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
WP_Block_Metadata_Registry:: (7 methods):
register_collection()
get_metadata()
find_collection_path()
has_metadata()
default_identifier_callback()
get_wpinc_dir()
get_plugin_dir()
Class: WP_Block_Metadata_Registry - X-Ref
Class used for managing block metadata collections.register_collection( $path, $manifest ) X-Ref |
Registers a block metadata collection. 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: ``` 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 ); ``` param: string $path The absolute base path for the collection ( e.g., WP_PLUGIN_DIR . '/my-plugin/blocks/' ). param: string $manifest The absolute path to the manifest file containing the metadata collection. return: bool True if the collection was registered successfully, false otherwise. |
get_metadata( $file_or_folder ) X-Ref |
Retrieves block metadata for a given block within a specific collection. This method uses the registered collections to efficiently lookup block metadata without reading individual `block.json` files. param: string $file_or_folder The path to the file or folder containing the block. return: array|null The block metadata for the block, or null if not found. |
find_collection_path( $file_or_folder ) X-Ref |
Finds the collection path for a given file or folder. param: string $file_or_folder The path to the file or folder. return: string|null The collection path if found, or null if not found. |
has_metadata( $file_or_folder ) X-Ref |
Checks if metadata exists for a given block name in a specific collection. param: string $file_or_folder The path to the file or folder containing the block metadata. return: bool True if metadata exists for the block, false otherwise. |
default_identifier_callback( $path ) X-Ref |
Default identifier function to determine the block identifier from a given path. This function extracts the block identifier from the path: - For 'block.json' files, it uses the parent directory name. - For directories, it uses the directory name itself. - For empty paths, it returns an empty string. For example: - Path: '/wp-content/plugins/my-plugin/blocks/example/block.json' Identifier: 'example' - Path: '/wp-content/plugins/my-plugin/blocks/another-block' Identifier: 'another-block' This default behavior matches the standard WordPress block structure. param: string $path The file or folder path to determine the block identifier from. return: string The block identifier, or an empty string if the path is empty. |
get_wpinc_dir() X-Ref |
Gets the WordPress 'wp-includes' directory path. return: string The WordPress 'wp-includes' directory path. |
get_plugin_dir() X-Ref |
Gets the normalized WordPress plugin directory path. return: string The normalized WordPress plugin directory path. |
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |