groups_accept_membership_request( int $membership_id, int $user_id, int $group_id )

Accept a pending group membership request.

Description

Parameters

$membership_id

(Required) Deprecated 1.3.5

$user_id

(Required) Required. ID of the user who requested membership. Provide this value along with $group_id to override $membership_id.

$group_id

(Required) Required. ID of the group to which membership is being requested. Provide this value along with $user_id to override $membership_id.

Return

(bool) True on success, false on failure.

Source

File: bp-groups/bp-groups-functions.php

function groups_accept_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) {

	if ( !empty( $user_id ) && !empty( $group_id ) ) {
		$membership = new BP_Groups_Member( $user_id, $group_id );
	} else {
		$membership = new BP_Groups_Member( false, false, $membership_id );
	}

	$membership->accept_request();

	if ( !$membership->save() ) {
		return false;
	}

	// Check if the user has an outstanding invite, if so delete it.
	if ( groups_check_user_has_invite( $membership->user_id, $membership->group_id ) ) {
		groups_delete_invite( $membership->user_id, $membership->group_id );
	}

	/**
	 * Fires after a group membership request has been accepted.
	 *
	 * @since BuddyPress 1.0.0
	 *
	 * @param int  $user_id  ID of the user who accepted membership.
	 * @param int  $group_id ID of the group that was accepted membership to.
	 * @param bool $value    If membership was accepted.
	 */
	do_action( 'groups_membership_accepted', $membership->user_id, $membership->group_id, true );

	return true;
}

Changelog

Changelog
Version Description
BuddyPress 5.0.0 Deprecated $membership_id argument. BuddyPress 5.0.0 Deprecated $membership_id argument.
BuddyPress 1.0.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.