WC_CLI_REST_Command::get_item()publicWC 1.0

Get a single item.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$WC_CLI_REST_Command = new WC_CLI_REST_Command();
$WC_CLI_REST_Command->get_item( $args, $assoc_args );
$args(массив) (обязательный)
WP-CLI positional arguments.
$assoc_args(массив) (обязательный)
WP-CLI associative arguments.

Код WC_CLI_REST_Command::get_item() WC 8.7.0

public function get_item( $args, $assoc_args ) {
	$route                           = $this->get_filled_route( $args );
	list( $status, $body, $headers ) = $this->do_request( 'GET', $route, $assoc_args );

	if ( ! empty( $assoc_args['fields'] ) ) {
		$body = self::limit_item_to_fields( $body, $assoc_args['fields'] );
	}

	if ( empty( $assoc_args['format'] ) ) {
		$assoc_args['format'] = 'table';
	}

	if ( 'headers' === $assoc_args['format'] ) {
		echo wp_json_encode( $headers );
	} elseif ( 'body' === $assoc_args['format'] ) {
		echo wp_json_encode( $body );
	} elseif ( 'envelope' === $assoc_args['format'] ) {
		echo wp_json_encode(
			array(
				'body'    => $body,
				'headers' => $headers,
				'status'  => $status,
			)
		);
	} else {
		$formatter = $this->get_formatter( $assoc_args );
		$formatter->display_item( $body );
	}
}