public function add( $args, $assoc_args ) {

		list( $name, $sidebar_id ) = $args;
		$position                  = Utils\get_flag_value( $args, 2, 1 ) - 1;
		$this->validate_sidebar( $sidebar_id );

		$widget = $this->get_widget_obj( $name );
		if ( false === $widget ) {
			WP_CLI::error( 'Invalid widget type.' );
		}

		/*
		 * Adding a widget is as easy as:
		 * 1. Creating a new widget option
		 * 2. Adding the widget to the sidebar
		 * 3. Positioning appropriately
		 */
		$widget_options = $this->get_widget_options( $name );
		$option_keys    = $widget_options;
		if ( ! isset( $widget_options['_multiwidget'] ) ) {
			$widget_options['_multiwidget'] = 1;
		}
		unset( $option_keys['_multiwidget'] );
		$option_keys                     = array_keys( $option_keys );
		$last_key                        = array_pop( $option_keys );
		$option_index                    = $last_key + 1;
		$widget_options[ $option_index ] = $this->sanitize_widget_options( $name, $assoc_args, array() );
		$this->update_widget_options( $name, $widget_options );

		$widget_id = $name . '-' . $option_index;
		$this->move_sidebar_widget( $widget_id, null, $sidebar_id, null, $position );

		WP_CLI::success( 'Added widget to sidebar.' );

	}
public function add( $args, $assoc_args ) {

		list( $name, $sidebar_id ) = $args;
		$position                  = Utils\get_flag_value( $args, 2, 1 ) - 1;
		$this->validate_sidebar( $sidebar_id );

		$widget = $this->get_widget_obj( $name );
		if ( false === $widget ) {
			WP_CLI::error( 'Invalid widget type.' );
		}

		/*
		 * Adding a widget is as easy as:
		 * 1. Creating a new widget option
		 * 2. Adding the widget to the sidebar
		 * 3. Positioning appropriately
		 */
		$widget_options = $this->get_widget_options( $name );
		$option_keys    = $widget_options;
		if ( ! isset( $widget_options['_multiwidget'] ) ) {
			$widget_options['_multiwidget'] = 1;
		}
		unset( $option_keys['_multiwidget'] );
		$option_keys                     = array_keys( $option_keys );
		$last_key                        = array_pop( $option_keys );
		$option_index                    = $last_key + 1;
		$widget_options[ $option_index ] = $this->sanitize_widget_options( $name, $assoc_args, array() );
		$this->update_widget_options( $name, $widget_options );

		$widget_id = $name . '-' . $option_index;
		$this->move_sidebar_widget( $widget_id, null, $sidebar_id, null, $position );

		WP_CLI::success( 'Added widget to sidebar.' );

	}
public function add ( $ args , $ assoc_args ) { list ( $ name , $ sidebar_id ) = $ args ; $ position = Utils \ get_flag_value ( $ args , 2 , 1 ) - 1 ; $ this -> validate_sidebar ( $ sidebar_id ) ; $ widget = $ this -> get_widget_obj ( $ name ) ; if ( false === $ widget ) { WP_CLI :: error ( 'Invalid widget type.' ) ; } /*
		 * Adding a widget is as easy as:
		 * 1. Creating a new widget option
		 * 2. Adding the widget to the sidebar
		 * 3. Positioning appropriately
		 */ $ widget_options = $ this -> get_widget_options ( $ name ) ; $ option_keys = $ widget_options ; if ( ! isset ( $ widget_options [ '_multiwidget' ] ) ) { $ widget_options [ '_multiwidget' ] = 1 ; } unset ( $ option_keys [ '_multiwidget' ] ) ; $ option_keys = array_keys ( $ option_keys ) ; $ last_key = array_pop ( $ option_keys ) ; $ option_index = $ last_key + 1 ; $ widget_options [ $ option_index ] = $ this -> sanitize_widget_options ( $ name , $ assoc_args , array ( ) ) ; $ this -> update_widget_options ( $ name , $ widget_options ) ; $ widget_id = $ name . '-' . $ option_index ; $ this -> move_sidebar_widget ( $ widget_id , null , $ sidebar_id , null , $ position ) ; WP_CLI :: success ( 'Added widget to sidebar.' ) ; }
Adds a widget to a sidebar.

Creates a new widget entry in the database, and associates it with the
sidebar.

## OPTIONS

<name>
: Widget name.

<sidebar-id>
: ID for the corresponding sidebar.

[<position>]
: Widget's current position within the sidebar. Defaults to last

[--<field>=<value>]
: Widget option to add, with its new value

## EXAMPLES

# Add a new calendar widget to sidebar-1 with title "Calendar"
$ wp widget add calendar sidebar-1 2 --title="Calendar"
Success: Added widget to sidebar.

@subcommand add
Adds a widget to a sidebar .