WC_CLI_REST_Command::limit_item_to_fields()private staticWC 1.0

Reduce an item to specific fields.

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

Хуков нет.

Возвращает

Массив.

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

$result = WC_CLI_REST_Command::limit_item_to_fields( $item, $fields );
$item(массив) (обязательный)
Item to reduce.
$fields(массив) (обязательный)
Fields to keep.

Код WC_CLI_REST_Command::limit_item_to_fields() WC 8.7.0

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