WP_Block_Metadata_Registry::is_valid_collection_path( string $path, string[] $collection_roots ): bool

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.

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

Parameters

$pathstringrequired
Normalized block metadata collection path, without trailing slash.
$collection_rootsstring[]required
List of normalized collection root paths, without trailing slashes.

Return

bool True if the path is allowed, false otherwise.

Source

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

Changelog

VersionDescription
6.7.2Introduced.

User Contributed Notes

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