22
33use WP_CLI \Entity \RecursiveDataStructureTraverser ;
44use WP_CLI \Utils ;
5+ use WP_CLI \Entity \Utils as EntityUtils ;
56
67/**
78 * Retrieves and sets site options, including plugin and WordPress settings.
@@ -124,7 +125,7 @@ public function add( $args, $assoc_args ) {
124125 $ value = WP_CLI ::get_value_from_arg_or_stdin ( $ args , 1 );
125126 $ value = WP_CLI ::read_value ( $ value , $ assoc_args );
126127
127- if ( \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'autoload ' ) === 'no ' ) {
128+ if ( Utils \get_flag_value ( $ assoc_args , 'autoload ' ) === 'no ' ) {
128129 $ autoload = 'no ' ;
129130 } else {
130131 $ autoload = 'yes ' ;
@@ -265,7 +266,7 @@ public function list_( $args, $assoc_args ) {
265266 $ fields = explode ( ', ' , $ assoc_args ['fields ' ] );
266267 }
267268
268- if ( \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'format ' ) === 'total_bytes ' ) {
269+ if ( Utils \get_flag_value ( $ assoc_args , 'format ' ) === 'total_bytes ' ) {
269270 $ fields = array ( 'size_bytes ' );
270271 $ size_query = ",SUM(LENGTH(option_value)) AS `size_bytes` " ;
271272 }
@@ -305,8 +306,8 @@ public function list_( $args, $assoc_args ) {
305306 $ results = $ wpdb ->get_results ( "SELECT `option_name`,`option_value`,`autoload` " . $ size_query
306307 . " FROM ` $ wpdb ->options ` {$ where }" );
307308
308- $ orderby = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'orderby ' );
309- $ order = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'order ' );
309+ $ orderby = Utils \get_flag_value ( $ assoc_args , 'orderby ' );
310+ $ order = Utils \get_flag_value ( $ assoc_args , 'order ' );
310311
311312 // Sort result.
312313 if ( 'option_id ' !== $ orderby ) {
@@ -328,7 +329,7 @@ public function list_( $args, $assoc_args ) {
328329 }
329330 }
330331
331- if ( \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'format ' ) === 'total_bytes ' ) {
332+ if ( Utils \get_flag_value ( $ assoc_args , 'format ' ) === 'total_bytes ' ) {
332333 WP_CLI ::line ( $ results [0 ]->size_bytes );
333334 } else {
334335 $ formatter = new \WP_CLI \Formatter (
@@ -406,7 +407,7 @@ public function update( $args, $assoc_args ) {
406407 $ value = WP_CLI ::get_value_from_arg_or_stdin ( $ args , 1 );
407408 $ value = WP_CLI ::read_value ( $ value , $ assoc_args );
408409
409- $ autoload = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'autoload ' );
410+ $ autoload = Utils \get_flag_value ( $ assoc_args , 'autoload ' );
410411 if ( ! in_array ( $ autoload , array ( 'yes ' , 'no ' ) ) ) {
411412 $ autoload = null ;
412413 }
@@ -544,12 +545,13 @@ public function patch( $args, $assoc_args ) {
544545
545546 if ( 'delete ' == $ action ) {
546547 $ patch_value = null ;
547- } elseif ( \WP_CLI \Entity \Utils::has_stdin () ) {
548- $ stdin_value = WP_CLI ::get_value_from_arg_or_stdin ( $ args , -1 );
549- $ patch_value = WP_CLI ::read_value ( trim ( $ stdin_value ), $ assoc_args );
550548 } else {
551- // Take the patch value as the last positional argument. Mutates $key_path to be 1 element shorter!
552- $ patch_value = WP_CLI ::read_value ( array_pop ( $ key_path ), $ assoc_args );
549+ $ stdin_value = EntityUtils::has_stdin ()
550+ ? trim ( WP_CLI ::get_value_from_arg_or_stdin ( $ args , -1 ) )
551+ : null ;
552+ $ patch_value = ! empty ( $ stdin_value )
553+ ? WP_CLI ::read_value ( $ stdin_value , $ assoc_args )
554+ : WP_CLI ::read_value ( array_pop ( $ key_path ), $ assoc_args );
553555 }
554556
555557 /* Need to make a copy of $current_value here as it is modified by reference */
0 commit comments