@@ -596,6 +596,8 @@ public function size( $args, $assoc_args ) {
596596 $ rows = array ();
597597 $ fields = array ( 'Name ' , 'Size ' );
598598
599+ $ default_unit = ( empty ( $ size_format ) ) ? ' B ' : '' ;
600+
599601 if ( $ tables ) {
600602
601603 // Add all of the table sizes
@@ -612,7 +614,7 @@ public function size( $args, $assoc_args ) {
612614 // Add the table size to the list.
613615 $ rows [] = array (
614616 'Name ' => $ table_name ,
615- 'Size ' => strtoupper ( size_format ( $ table_bytes ) ) ,
617+ 'Size ' => strtoupper ( $ table_bytes ) . $ default_unit ,
616618 );
617619 }
618620 } else {
@@ -627,39 +629,43 @@ public function size( $args, $assoc_args ) {
627629 // Add the database size to the list.
628630 $ rows [] = array (
629631 'Name ' => DB_NAME ,
630- 'Size ' => strtoupper ( size_format ( $ db_bytes ) ) ,
632+ 'Size ' => strtoupper ( $ db_bytes ) . $ default_unit ,
631633 );
632634 }
633635
634- if ( ! empty ( $ size_format ) && isset ( $ db_bytes ) && ! $ tables ) {
636+ if ( ! empty ( $ size_format ) ) {
637+ foreach ( $ rows as $ index => $ row ) {
638+ // These added WP 4.4.0.
639+ if ( ! defined ( 'KB_IN_BYTES ' ) ) {
640+ define ( 'KB_IN_BYTES ' , 1024 );
641+ }
642+ if ( ! defined ( 'MB_IN_BYTES ' ) ) {
643+ define ( 'MB_IN_BYTES ' , 1024 * KB_IN_BYTES );
644+ }
635645
636- // These added WP 4.4.0.
637- if ( ! defined ( 'KB_IN_BYTES ' ) ) {
638- define ( 'KB_IN_BYTES ' , 1024 );
639- }
640- if ( ! defined ( 'MB_IN_BYTES ' ) ) {
641- define ( 'MB_IN_BYTES ' , 1024 * KB_IN_BYTES );
642- }
646+ // Display the database size as a number.
647+ switch ( $ size_format ) {
648+ case 'mb ' :
649+ $ divisor = MB_IN_BYTES ;
650+ break ;
643651
644- // Display the database size as a number.
645- switch ( $ size_format ) {
646- case 'mb ' :
647- $ divisor = MB_IN_BYTES ;
648- break ;
652+ case 'kb ' :
653+ $ divisor = KB_IN_BYTES ;
654+ break ;
649655
650- case 'kb ' :
651- $ divisor = KB_IN_BYTES ;
652- break ;
656+ case 'b ' :
657+ default :
658+ $ divisor = 1 ;
659+ break ;
660+ }
653661
654- case 'b ' :
655- default :
656- $ divisor = 1 ;
657- break ;
662+ $ rows [ $ index ]['Size ' ] = ceil ( $ row ['Size ' ] / $ divisor ) . " " . strtoupper ( $ size_format );
658663 }
664+ }
659665
660- WP_CLI ::Line ( ceil ( $ db_bytes / $ divisor ) );
666+ if ( ! empty ( $ size_format ) && ! $ tables ) {
667+ WP_CLI ::Line ( filter_var ( $ rows [0 ]['Size ' ], FILTER_SANITIZE_NUMBER_INT ) );
661668 } else {
662-
663669 // Display the rows.
664670 $ args = array (
665671 'format ' => $ format ,
0 commit comments