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

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

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

VersionDescription
6.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.