@@ -130,11 +130,14 @@ public function list_( $args, $assoc_args ) {
130130 * @subcommand add
131131 */
132132 public function add ( $ args , $ assoc_args ) {
133-
134133 list ( $ name , $ sidebar_id ) = $ args ;
135- $ position = Utils \get_flag_value ( $ args , 2 , 1 ) - 1 ;
134+
136135 $ this ->validate_sidebar ( $ sidebar_id );
137136
137+ $ position = count ( $ args ) > 2
138+ ? $ args [2 ] - 1
139+ : count ( $ this ->get_sidebar_widgets ( $ sidebar_id ) );
140+
138141 $ widget = $ this ->get_widget_obj ( $ name );
139142 if ( false === $ widget ) {
140143 WP_CLI ::error ( 'Invalid widget type. ' );
@@ -300,7 +303,13 @@ public function deactivate( $args, $assoc_args ) {
300303 continue ;
301304 }
302305
303- $ this ->move_sidebar_widget ( $ widget_id , $ sidebar_id , 'wp_inactive_widgets ' , $ sidebar_index , 0 );
306+ $ this ->move_sidebar_widget (
307+ $ widget_id ,
308+ $ sidebar_id ,
309+ 'wp_inactive_widgets ' ,
310+ $ sidebar_index ,
311+ count ( $ this ->get_sidebar_widgets ( 'wp_inactive_widgets ' ) )
312+ );
304313
305314 $ count ++;
306315
@@ -427,7 +436,13 @@ public function reset( $args, $assoc_args ) {
427436 foreach ( $ widgets as $ widget ) {
428437 $ widget_id = $ widget ->id ;
429438 list ( $ name , $ option_index , $ new_sidebar_id , $ sidebar_index ) = $ this ->get_widget_data ( $ widget_id );
430- $ this ->move_sidebar_widget ( $ widget_id , $ new_sidebar_id , 'wp_inactive_widgets ' , $ sidebar_index , 0 );
439+ $ this ->move_sidebar_widget (
440+ $ widget_id ,
441+ $ new_sidebar_id ,
442+ 'wp_inactive_widgets ' ,
443+ $ sidebar_index ,
444+ count ( $ this ->get_sidebar_widgets ( 'wp_inactive_widgets ' ) )
445+ );
431446 }
432447 WP_CLI ::log ( sprintf ( "Sidebar '%s' reset. " , $ sidebar_id ) );
433448 $ count ++;
0 commit comments