BP_REST_Group_Invites_Endpoint::delete_item( WP_REST_Request $request )

Remove (reject/delete) a group invitation.

Description

Parameters

$request

(Required) Full details about the request.

Return

(WP_REST_Response) | WP_Error

Source

File: bp-groups/classes/class-bp-rest-group-invites-endpoint.php

792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
public function delete_item( $request ) {
    $request->set_param( 'context', 'edit' );
 
    $user_id = bp_loggedin_user_id();
    $invite  = $this->fetch_single_invite( $request['invite_id'] );
 
    // Set the invite response before it is deleted.
    $previous = $this->prepare_item_for_response( $invite, $request );
 
    /**
     * If this change is being initiated by the invited user,
     * use the `reject` function.
     */
    if ( $user_id === $invite->user_id ) {
        $deleted = groups_reject_invite( $invite->user_id, $invite->item_id, $invite->inviter_id );
        /**
         * Otherwise, this change is being initiated by a group admin, site admin,
         * or the inviter, and we should use the `uninvite` function.
         */
    } else {
        $deleted = groups_uninvite_user( $invite->user_id, $invite->item_id, $invite->inviter_id );
    }
 
    if ( ! $deleted ) {
        return new WP_Error(
            'bp_rest_group_invite_cannot_delete_item',
            __( 'Could not delete group invitation.', 'buddyboss' ),
            array(
                'status' => rest_authorization_required_code(),
            )
        );
    }
 
    // Build the response.
    $response = new WP_REST_Response();
    $response->set_data(
        array(
            'deleted'  => true,
            'previous' => $previous->get_data(),
        )
    );
 
    $user  = bp_rest_get_user( $invite->user_id );
    $group = $this->groups_endpoint->get_group_object( $invite->item_id );
 
    /**
     * Fires after a group invite is deleted via the REST API.
     *
     * @param WP_User          $user     The invited 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_invites_delete_item', $user, $group, $response, $request );
 
    return $response;
}

Changelog

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.