BP_REST_Group_Membership_Request_Endpoint::update_item( WP_REST_Request $request )

Accept or 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 update_item( $request ) {
		$group_request = $this->fetch_single_membership_request( $request['request_id'] );
		$success       = groups_accept_membership_request( false, $group_request->user_id, $group_request->item_id );
		if ( ! $success ) {
			return new WP_Error(
				'bp_rest_group_member_request_cannot_update_item',
				__( 'There was an error accepting the membership request.', 'buddypress' ),
				array(
					'status' => 500,
				)
			);
		}

		// Setting context.
		$request->set_param( 'context', 'edit' );

		$g_member = new BP_Groups_Member( $group_request->user_id, $group_request->item_id );

		$retval = array(
			$this->prepare_response_for_collection(
				$this->group_members_endpoint->prepare_item_for_response( $g_member, $request )
			),
		);

		$response = rest_ensure_response( $retval );
		$group    = $this->groups_endpoint->get_group_object( $group_request->item_id );

		/**
		 * Fires after a group membership request is accepted/rejected via the REST API.
		 *
		 * @since 5.0.0
		 *
		 * @param BP_Groups_Member $g_member The groups member object.
		 * @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_update_item', $g_member, $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.