BP_Groups_Invitation_Manager::run_acceptance_action( string $type = 'invite', array $r )

This is where custom actions are added to run when an invitation or request is accepted.

Description

Parameters

$type

(string) (Optional) Are we accepting an invitation or request?

Default value: 'invite'

$r

(array) (Required) Parameters that describe the invitation being accepted.

Return

(bool) True on success, false on failure.

Source

File: bp-groups/classes/class-bp-groups-invitation-manager.php

	public function run_acceptance_action( $type = 'invite', $r  ) {
		// If the user is already a member (because BP at one point allowed two invitations to
		// slip through), return early.
		if ( groups_is_user_member( $r['user_id'], $r['item_id'] ) ) {
			return true;
		}

		// Create the new membership
		$member = new BP_Groups_Member( $r['user_id'], $r['item_id'] );

		if ( 'request' === $type ) {
			$member->accept_request();
		} else {
			$member->accept_invite();
		}

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

		if ( 'request' === $type ) {
			/**
			 * 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', $r['user_id'], $r['item_id'], true );
		} else {
			// Get an inviter_id from the invitation.
			$invites = groups_get_invites( $r );
			$inviter_id = 0;
			if ( $invites ) {
				$inviter_id = current( $invites )->inviter_id;
			}

			/**
			 * Fires after a user has accepted a group invite.
			 *
			 * @since BuddyPress 1.0.0
			 * @since BuddyPress 2.8.0 The $inviter_id arg was added.
			 *
			 * @param int $user_id    ID of the user who accepted the group invite.
			 * @param int $group_id   ID of the group being accepted to.
			 * @param int $inviter_id ID of the user who invited this user to the group.
			 */
			do_action( 'groups_accept_invite', $r['user_id'], $r['item_id'], $inviter_id );
		}

		// Modify group meta.
		groups_update_groupmeta( $r['item_id'], 'last_activity', bp_core_current_time() );

		return true;
	}

Changelog

Changelog
Version Description
BuddyBoss 1.3.5 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.