W3cubDocs

/WordPress

WP_Block_Metadata_Registry::find_collection_path( string $file_or_folder ): string|null

Finds the collection path for a given file or folder.

Parameters

$file_or_folderstringrequired
The path to the file or folder.

Return

string|null The collection path if found, or null if not found.

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.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_block_metadata_registry/find_collection_path