MetaDataUtil
in package
Utility methods for handling meta data in REST API requests.
Tags
Table of Contents
- normalize() : array<string|int, array<string|int, mixed>>
- Normalize an array of raw meta data entries from a REST API request.
- update() : void
- Normalize and process meta data entries from a REST API request.
Methods
normalize()
Normalize an array of raw meta data entries from a REST API request.
public
static normalize(array<string|int, mixed> $meta_data[, mixed $default_id = '' ]) : array<string|int, array<string|int, mixed>>
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.
Parameters
- $meta_data : array<string|int, mixed>
-
Raw meta data array from the request.
- $default_id : mixed = ''
-
Default value for 'id' when not provided (default '').
Tags
Return values
array<string|int, array<string|int, mixed>> — Normalized meta data entries.update()
Normalize and process meta data entries from a REST API request.
public
static update(mixed $meta_data, WC_Data $target[, mixed $default_id = '' ]) : void
Skips entries without a key, applies defaults for missing 'value' and 'id' fields, then calls update_meta_data on the given WC_Data object for each valid entry.
Parameters
- $meta_data : mixed
-
Raw meta data from the request (non-array values are ignored).
- $target : WC_Data
-
A WC_Data object to call update_meta_data on.
- $default_id : mixed = ''
-
Default value for 'id' when not provided (default '').
