Default identifier function to determine the block identifier from a given path.
Description
This function extracts the block identifier from the path: <ul> <li>For 'block.json' files, it uses the parent directory name.</li> <li>For directories, it uses the directory name itself.</li> <li>For empty paths, it returns an empty string.</li> </ul> For example: <ul> <li>Path: '/wp-content/plugins/my-plugin/blocks/example/block.json' Identifier: 'example'</li> <li>Path: '/wp-content/plugins/my-plugin/blocks/another-block' Identifier: 'another-block'</li> </ul> This default behavior matches the standard WordPress block structure.
Parameters
$pathstring
The normalized file or folder path to determine the block identifier from.
Return
string
The block identifier, or an empty string if the path is empty.
Uses · 1
str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
288privatestaticfunctiondefault_identifier_callback($path){289// Ensure $path is not empty to prevent unexpected behavior.290if(empty($path)){291return'';292}293294if(str_ends_with($path,'block.json')){295// Return the parent directory name if it's a block.json file.296returnbasename(dirname($path));297}298299// Otherwise, assume it's a directory and return its name.300returnbasename($path);301}
History
Introduced in 6.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-block-metadata-registry.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.