BP_REST_Notifications_Endpoint::update_item( WP_REST_Request $request )
Update a notification.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-notifications/classes/class-bp-rest-notifications-endpoint.php
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | public function update_item( $request ) { // Setting context. $request ->set_param( 'context' , 'edit' ); $notification = $this ->get_notification_object( $request ); if ( $request [ 'is_new' ] === $notification ->is_new ) { return new WP_Error( 'bp_rest_user_cannot_update_notification_status' , __( 'Notification is already with the status you are trying to update into.' , 'buddyboss' ), array ( 'status' => 500, ) ); } $updated = BP_Notifications_Notification::update( array ( 'is_new' => $request [ 'is_new' ] ), array ( 'id' => $notification ->id ) ); if ( ! (bool) $updated ) { return new WP_Error( 'bp_rest_user_cannot_update_notification' , __( 'Cannot update the status of this notification.' , 'buddyboss' ), array ( 'status' => 500, ) ); } // Make sure to update the status of the notification. $notification = $this ->prepare_item_for_database( $request ); // Update additional fields. $fields_update = $this ->update_additional_fields_for_object( $notification , $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update ; } $retval = $this ->prepare_response_for_collection( $this ->prepare_item_for_response( $notification , $request ) ); $response = rest_ensure_response( $retval ); /** * Fires after a notification is updated via the REST API. * * @param BP_Notifications_Notification $notification The updated notification. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ do_action( 'bp_rest_notifications_update_item' , $notification , $response , $request ); return $response ; } |
Changelog
Version | Description |
---|---|
0.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.