BP_REST_Group_Membership_Request_Endpoint::delete_item( WP_REST_Request $request )
Reject a pending group membership request.
Description
Parameters
- $request
-
(Required) Full data about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-groups/classes/class-bp-rest-group-membership-request-endpoint.php
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | public function delete_item( $request ) { // Setting context. $request ->set_param( 'context' , 'edit' ); // Get invite. $group_request = $this ->fetch_single_membership_request( $request [ 'request_id' ] ); // Set the invite response before it is deleted. $previous = $this ->prepare_item_for_response( $group_request , $request ); /** * If this change is being initiated by the requesting user, * use the `delete` function. */ if ( bp_loggedin_user_id() === $group_request ->user_id ) { $success = groups_delete_membership_request( false, $group_request ->user_id, $group_request ->item_id ); /** * Otherwise, this change is being initiated by a group admin or site admin, * and we should use the `reject` function. */ } else { $success = groups_reject_membership_request( false, $group_request ->user_id, $group_request ->item_id ); } if ( ! $success ) { return new WP_Error( 'bp_rest_group_membership_requests_cannot_delete_item' , __( 'There was an error rejecting the membership request.' , 'buddyboss' ), array ( 'status' => 500, ) ); } // Build the response. $response = new WP_REST_Response(); $response ->set_data( array ( 'deleted' => true, 'previous' => $previous ->get_data(), ) ); $user = bp_rest_get_user( $group_request ->user_id ); $group = $this ->groups_endpoint->get_group_object( $group_request ->item_id ); /** * Fires after a group membership request is rejected via the REST API. * * @param WP_User $user The user. * @param BP_Groups_Group $group The group 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_group_membership_requests_delete_item' , $user , $group , $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.