BP_REST_Messages_Endpoint::delete_item( WP_REST_Request $request )
Delete a thread.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-messages/classes/class-bp-rest-messages-endpoint.php
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | public function delete_item( $request ) { // Setting context. $request ->set_param( 'context' , 'edit' ); // Get the thread before it's deleted. $thread = $this ->get_thread_object( $request [ 'id' ] ); $thread ->recipients = $thread ->get_recipients( $thread ->thread_id ); $previous = $this ->prepare_item_for_response( $thread , $request ); $user_id = bp_loggedin_user_id(); if ( ! empty ( $request [ 'user_id' ] ) ) { $user_id = $request [ 'user_id' ]; } // Check the user is one of the recipients. $recipient_ids = wp_parse_id_list( wp_list_pluck( $thread ->recipients, 'user_id' ) ); // Delete a thread. if ( ! in_array( $user_id , $recipient_ids , true ) || ! messages_delete_thread( $thread ->thread_id, $user_id ) ) { return new WP_Error( 'bp_rest_messages_delete_thread_failed' , __( 'There was an error trying to delete the thread.' , 'buddyboss' ), array ( 'status' => 500, ) ); } // Build the response. $response = new WP_REST_Response(); $response ->set_data( array ( 'deleted' => true, 'previous' => $previous ->get_data(), ) ); /** * Fires after a thread is deleted via the REST API. * * @param BP_Messages_Thread $thread Thread object. * @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_messages_delete_item' , $thread , $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.