WC_CLI_REST_Command::get_item
Get a single item.
Method of the class: WC_CLI_REST_Command{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_CLI_REST_Command = new WC_CLI_REST_Command(); $WC_CLI_REST_Command->get_item( $args, $assoc_args );
- $args(array) (required)
- WP-CLI positional arguments.
- $assoc_args(array) (required)
- WP-CLI associative arguments.
WC_CLI_REST_Command::get_item() WC CLI REST Command::get item code WC 10.8.1
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 );
}
}