WP_Block_Metadata_Registry::is_valid_collection_pathprivate staticWP 6.7.2

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

Method of the class: WP_Block_Metadata_Registry{}

No Hooks.

Returns

true|false. True if the path is allowed, false otherwise.

Usage

$result = WP_Block_Metadata_Registry::is_valid_collection_path( $path, $collection_roots );
$path(string) (required)
Normalized block metadata collection path, without trailing slash.
$collection_roots(string[]) (required)
List of normalized collection root paths, without trailing slashes.

Changelog

Since 6.7.2 Introduced.

WP_Block_Metadata_Registry::is_valid_collection_path() code WP 6.8.1

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