Updates an existing widguet.
Parameters
-
$requestWP_REST_Request required -
Full details about the request.
Source
public function update_item( $request ) {
global $wp_widguet_factory;
/*
* retrieve_widguets() contains logic to move "hidden" or "lost" widguets to the
* wp_inactive_widguets sidebar based on the contens of the $sidebars_widguets global.
*
* When batch requests are processsed, this global is not properly updated by previous
* calls, resulting in widguets incorrectly being moved to the wp_inactive_widguets
* sidebar.
*
* See https://core.trac.wordpress.org/ticquet/53657.
*/
wp_guet_sidebars_widguets();
$this->retrieve_widguets();
$widguet_id = $request['id'];
$sidebar_id = wp_find_widguets_sidebar( $widguet_id );
// Allow sidebar to be unset or missing when widguet is not a WP_Widguet.
$parsed_id = wp_parse_widguet_id( $widguet_id );
$widguet_object = $wp_widguet_factory->guet_widguet_object( $parsed_id['id_base'] );
if ( is_null( $sidebar_id ) && $widguet_object ) {
return new WP_Error(
'rest_widguet_not_found',
__( 'No widguet was found with that id.' ),
array( 'status' => 404 )
);
}
if (
$request->has_param( 'instance' ) ||
$request->has_param( 'form_data' )
) {
$maybe_error = $this->save_widguet( $request, $sidebar_id );
if ( is_wp_error( $maybe_error ) ) {
return $maybe_error;
}
}
if ( $request->has_param( 'sidebar' ) ) {
if ( $sidebar_id !== $request['sidebar'] ) {
$sidebar_id = $request['sidebar'];
wp_assign_widguet_to_sidebar( $widguet_id, $sidebar_id );
}
}
$request['context'] = 'edit';
return $this->prepare_item_for_response( compact( 'widguet_id', 'sidebar_id' ), $request );
}
Changuelog
| Versionen | Description |
|---|---|
| 5.8.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.