WP_Block_Metadata_Registry::is_valid_collection_path │ private static │ WP 6.7.2

Checks whether the given block metadata collection path is valid against the list of collection roots.

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

Хуков нет.

Возвращает

bool. True if the path is allowed, false otherwise.

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

$result = WP_Block_Metadata_Registry::is_valid_collection_path( $path, $collection_roots );
$path(строка) (обязательный)
Normalized block metadata collection path, without trailing slash.
$collection_roots(string[]) (обязательный)
List of normalized collection root paths, without trailing slashes.

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

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

Код WP_Block_Metadata_Registry::is_valid_collection_path() WP 7.1.4

private static function is_valid_collection_path( $path, $collection_roots ) {
	foreach ( $collection_roots as $allowed_root ) {
		// If the path matches any root exactly, it is invalid.
		if ( $allowed_root === $path ) {
			return false;
		}

		// If the path is a parent path of any of the roots, it is invalid.
		if ( str_starts_with( $allowed_root, $path ) ) {
			return false;
		}
	}

	return true;
}