Automattic\WooCommerce\Api\Utils

SchemaHandle::find_metadatapublicWC 1.0

Filter-narrows view over {@see self::get_all_metadata()}.

Each filter argument independently restricts the result set; supplying multiple composes as AND. When $name is supplied, the surviving rows have their entries trimmed to the single matching entry; so a caller asking "which elements are marked X" gets focused rows back, not the full multi-entry shape.

Method of the class: SchemaHandle{}

No Hooks.

Returns

list. string, field: ?string, argument: ?string, enumValue: ?string, entries: array<string, bool|int|float|string|null>, authorization: list<array{attribute: string, args: list<mixed>}>}>

Usage

$SchemaHandle = new SchemaHandle();
$SchemaHandle->find_metadata( ?string $name, ?string $type, ?string $field, ?string $attribute ): array;
?string $name
.
Default: null
?string $type
.
Default: null
?string $field
.
Default: null
?string $attribute
.
Default: null

SchemaHandle::find_metadata() code WC 10.9.1

public function find_metadata( ?string $name = null, ?string $type = null, ?string $field = null, ?string $attribute = null ): array {
	$rows = $this->get_all_metadata();

	$result = array();
	foreach ( $rows as $row ) {
		if ( null !== $type && $row['type'] !== $type ) {
			continue;
		}
		if ( null !== $field && $row['field'] !== $field ) {
			continue;
		}
		if ( null !== $name ) {
			if ( ! array_key_exists( $name, $row['entries'] ) ) {
				continue;
			}
			$row['entries'] = array( $name => $row['entries'][ $name ] );
		}
		if ( null !== $attribute ) {
			$matching = array_values(
				array_filter(
					$row['authorization'],
					static fn( array $descriptor ): bool => ( $descriptor['attribute'] ?? null ) === $attribute,
				)
			);
			if ( empty( $matching ) ) {
				continue;
			}
			$row['authorization'] = $matching;
		}
		$result[] = $row;
	}

	return $result;
}