BP_REST_Group_Membership_Request_Endpoint::delete_item( WP_REST_Request $request )

Reject a pending group membership request.


Parameters Parameters

$request

(WP_REST_Request) (Required) Full data about the request.


Top ↑

Return Return

(WP_REST_Response|WP_Error)


Source Source

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

	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.', 'buddypress' ),
				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.
		 *
		 * @since 5.0.0
		 *
		 * @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.
		 */
		do_action( 'bp_rest_group_membership_requests_delete_item', $user, $group, $response, $request );

		return $response;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.