WC_CLI_REST_Command::limit_item_to_fields
Reduce an item to specific fields.
Method of the class: WC_CLI_REST_Command{}
No Hooks.
Returns
Array.
Usage
$result = WC_CLI_REST_Command::limit_item_to_fields( $item, $fields );
- $item(array) (required)
- Item to reduce.
- $fields(array) (required)
- Fields to keep.
WC_CLI_REST_Command::limit_item_to_fields() WC CLI REST Command::limit item to fields code WC 10.3.5
private static function limit_item_to_fields( $item, $fields ) {
if ( empty( $fields ) ) {
return $item;
}
if ( is_string( $fields ) ) {
$fields = explode( ',', $fields );
}
foreach ( $item as $i => $field ) {
if ( ! in_array( $i, $fields, true ) ) {
unset( $item[ $i ] );
}
}
return $item;
}