WP_CLI

Formatter::display_item()publicWP-CLI 1.0

Display a single item according to the output arguments.

Method of the class: Formatter{}

No Hooks.

Return

null. Nothing (null).

Usage

$Formatter = new Formatter();
$Formatter->display_item( $item, $ascii_pre_colorized );
$item(mixed) (required)
-
$ascii_pre_colorized(true|false|array)
A boolean or an array of booleans to pass to show_multiple_fields() if the item in the table is pre-colorized.
Default: false

Formatter::display_item() code WP-CLI 2.8.0-alpha

public function display_item( $item, $ascii_pre_colorized = false ) {
	if ( isset( $this->args['field'] ) ) {
		$item  = (object) $item;
		$key   = $this->find_item_key( $item, $this->args['field'] );
		$value = $item->$key;
		if ( in_array( $this->args['format'], [ 'table', 'csv' ], true ) && ( is_object( $value ) || is_array( $value ) ) ) {
			$value = json_encode( $value );
		}
		WP_CLI::print_value(
			$value,
			[
				'format' => $this->args['format'],
			]
		);
	} else {
		$this->show_multiple_fields( $item, $this->args['format'], $ascii_pre_colorized );
	}
}