WP_REST_Global_Styles_Controller::update_item()publicWP 5.9.0

Updates a single global style config.

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

No Hooks.

Return

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

Usage

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

Changelog

Since 5.9.0 Introduced.

Code of WP_REST_Global_Styles_Controller::update_item() WP 6.0

public function update_item( $request ) {
	$post_before = $this->get_post( $request['id'] );
	if ( is_wp_error( $post_before ) ) {
		return $post_before;
	}

	$changes = $this->prepare_item_for_database( $request );
	$result  = wp_update_post( wp_slash( (array) $changes ), true, false );
	if ( is_wp_error( $result ) ) {
		return $result;
	}

	$post          = get_post( $request['id'] );
	$fields_update = $this->update_additional_fields_for_object( $post, $request );
	if ( is_wp_error( $fields_update ) ) {
		return $fields_update;
	}

	wp_after_insert_post( $post, true, $post_before );

	$response = $this->prepare_item_for_response( $post, $request );

	return rest_ensure_response( $response );
}