Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

WC_CLI_REST_Command::limit_item_to_fields( array $item, array $fields )

Reduce an item to specific fields.


Description Description


Parameters Parameters

$item

(Required) Item to reduce.

$fields

(Required) Fields to keep.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/cli/class-wc-cli-rest-command.php

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


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.