@@ -596,6 +596,8 @@ public function size( $args, $assoc_args ) {
596
596
$ rows = array ();
597
597
$ fields = array ( 'Name ' , 'Size ' );
598
598
599
+ $ default_unit = ( empty ( $ size_format ) ) ? ' B ' : '' ;
600
+
599
601
if ( $ tables ) {
600
602
601
603
// Add all of the table sizes
@@ -612,7 +614,7 @@ public function size( $args, $assoc_args ) {
612
614
// Add the table size to the list.
613
615
$ rows [] = array (
614
616
'Name ' => $ table_name ,
615
- 'Size ' => strtoupper ( size_format ( $ table_bytes ) ) ,
617
+ 'Size ' => strtoupper ( $ table_bytes ) . $ default_unit ,
616
618
);
617
619
}
618
620
} else {
@@ -627,39 +629,43 @@ public function size( $args, $assoc_args ) {
627
629
// Add the database size to the list.
628
630
$ rows [] = array (
629
631
'Name ' => DB_NAME ,
630
- 'Size ' => strtoupper ( size_format ( $ db_bytes ) ) ,
632
+ 'Size ' => strtoupper ( $ db_bytes ) . $ default_unit ,
631
633
);
632
634
}
633
635
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
+ }
635
645
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 ;
643
651
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 ;
649
655
650
- case 'kb ' :
651
- $ divisor = KB_IN_BYTES ;
652
- break ;
656
+ case 'b ' :
657
+ default :
658
+ $ divisor = 1 ;
659
+ break ;
660
+ }
653
661
654
- case 'b ' :
655
- default :
656
- $ divisor = 1 ;
657
- break ;
662
+ $ rows [ $ index ]['Size ' ] = ceil ( $ row ['Size ' ] / $ divisor ) . " " . strtoupper ( $ size_format );
658
663
}
664
+ }
659
665
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 ) );
661
668
} else {
662
-
663
669
// Display the rows.
664
670
$ args = array (
665
671
'format ' => $ format ,
0 commit comments