}
$fields = array(
- 'ID',
- 'user_login',
- 'display_name',
- 'user_email',
- 'user_registered'
- );
+ 'ID',
+ 'user_login',
+ 'display_name',
+ 'user_email',
+ 'user_registered'
+ );
switch( $params['format'] ) {
case 'table':
if ( 'json' == $params['format'] )
echo json_encode( $output_users );
else
- WP_CLI\Utils\output_csv( $fields, $output_users );
+ WP_CLI\Utils\output_csv( $output_users, $fields );
break;
}
-
}
/**
/**
* Output data as CSV
*
- * @param array $headers Headers for the CSV (optional)
- * @param array $data Data for each row
+ * @param array $rows Array of rows to output
+ * @param array $headers List of CSV columns (optional)
*/
-function output_csv( $headers = array(), $data = array() ) {
+function output_csv( $rows, $headers = array() ) {
// Prepare the headers if they were specified
if ( ! empty( $headers ) )
fputcsv( STDOUT, $headers );
- foreach( $data as $row ) {
- $row = (array)$row;
+ foreach ( $rows as $row ) {
+ $row = (array) $row;
if ( ! empty( $headers ) ) {
$build_row = array();
- foreach( $headers as $key ) {
- $build_row[] = $row[$key];
+ foreach ( $headers as $key ) {
+ $build_row[] = $row[ $key ];
}
$row = $build_row;
}
fputcsv( STDOUT, $row );
}
}
+