WordPress at Your Fingertips
function is not described

WP_REST_Widgets_Controller::create_item() public WP 5.8.0

Creates a widget.

{} It's a method of the class: WP_REST_Widgets_Controller{}

No Hooks.

Return

WP_REST_Response|WP_Error. Response object on success, or WP_Error object on failure.

Usage

$WP_REST_Widgets_Controller = new WP_REST_Widgets_Controller();
$WP_REST_Widgets_Controller->create_item( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 5.8.0 Introduced.

Code of WP_REST_Widgets_Controller::create_item() WP 5.8.1

public function create_item( $request ) {
	$sidebar_id = $request['sidebar'];

	$widget_id = $this->save_widget( $request, $sidebar_id );

	if ( is_wp_error( $widget_id ) ) {
		return $widget_id;
	}

	wp_assign_widget_to_sidebar( $widget_id, $sidebar_id );

	$request['context'] = 'edit';

	$response = $this->prepare_item_for_response( compact( 'sidebar_id', 'widget_id' ), $request );

	if ( is_wp_error( $response ) ) {
		return $response;
	}

	$response->set_status( 201 );

	return $response;
}