Also:
- unset the 'format_content' field; it can be just as long as
'post_content'.
- unset the 'filter' field; it's a runtime value, not persistent data
return $status;
}
+ protected function assoc_array_to_table( $fields ) {
+ $rows = array();
+
+ foreach ( $fields as $field => $value ) {
+ if ( !is_string($value) ) {
+ $value = json_encode( $value );
+ }
+
+ $rows[] = (object) array(
+ 'Field' => $field,
+ 'Value' => $value
+ );
+ }
+
+ \WP_CLI\Utils\format_items( 'table', $rows, array( 'Field', 'Value' ) );
+ }
+
public function delete( $args, $assoc_args ) {
$status = 0;
exit( $status );
}
+
}
break;
case 'table':
- $items = array();
- foreach ( get_object_vars( $post ) as $field => $value ) {
- if ( 'post_content' === $field )
- continue;
-
- if ( !is_string($value) ) {
- $value = json_encode($value);
- }
-
- $item = new \stdClass;
- $item->Field = $field;
- $item->Value = $value;
- $items[] = $item;
- }
-
- \WP_CLI\Utils\format_items( $format, $items, array( 'Field', 'Value' ) );
+ $fields = get_object_vars( $post );
+ unset( $fields['filter'], $fields['post_content'], $fields['format_content'] );
+ $this->assoc_array_to_table( $fields );
break;
case 'json':