WP_Block_Metadata_Registry::find_collection_path()private staticWP 6.7.0

Finds the collection path for a given file or folder.

Метод класса: WP_Block_Metadata_Registry{}

Хуков нет.

Возвращает

Строку|null. The collection path if found, or null if not found.

Использование

$result = WP_Block_Metadata_Registry::find_collection_path( $file_or_folder );
$file_or_folder(строка) (обязательный)
The path to the file or folder.

Список изменений

С версии 6.7.0 Введена.

Код WP_Block_Metadata_Registry::find_collection_path() WP 6.7.1

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;
}