Finds the collection path for a given file or folder.
Parameters
$file_or_folder
stringrequired- The path to the file or folder.
Source
private static function find_collection_path( $file_or_folder ) {
if ( empty( $file_or_folder ) ) {
return null;
}
// Check the last matched collection first, since block registration usually happens in batches per plugin or theme.
$path = wp_normalize_path( rtrim( $file_or_folder, '/' ) );
if ( self::$last_matched_collection && str_starts_with( $path, self::$last_matched_collection ) ) {
return self::$last_matched_collection;
}
$collection_paths = array_keys( self::$collections );
foreach ( $collection_paths as $collection_path ) {
if ( str_starts_with( $path, $collection_path ) ) {
self::$last_matched_collection = $collection_path;
return $collection_path;
}
}
return null;
}
Changelog
Version | Description |
---|---|
6.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.