Automattic\WooCommerce\Utilities

MetaDataUtil::normalizepublic staticWC 10.8.0

Normalize an array of raw meta data entries from a REST API request.

Filters out entries without a key and applies default values for missing 'value' and 'id' fields. Each returned entry is guaranteed to have 'key', 'value', and 'id' set.

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

Хуков нет.

Возвращает

Массив[]. Normalized meta data entries.

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

$result = MetaDataUtil::normalize( $meta_data, $default_id ): array;
$meta_data(массив) (обязательный)
Raw meta data array from the request.
$default_id(разное)
Default value for 'id' when not provided (default '').
По умолчанию: ''

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

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

Код MetaDataUtil::normalize() WC 11.0.1

public static function normalize( array $meta_data, $default_id = '' ): array {
	$normalized = array();
	foreach ( $meta_data as $meta ) {
		if ( is_array( $meta ) && isset( $meta['key'] ) ) {
			$normalized[] = array(
				'key'   => $meta['key'],
				'value' => $meta['value'] ?? null,
				'id'    => $meta['id'] ?? $default_id,
			);
		}
	}
	return $normalized;
}