BP_Groups_Invitation_Manager::run_acceptance_action( string $type, array $r )

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


Parameters Parameters

$type

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

$r

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


Top ↑

Return Return

(bool) True on success, false on failure.


Source Source

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

	public function run_acceptance_action( $type, $r ) {
		if ( ! $type || ! in_array( $type, array( 'request', 'invite' ), true ) ) {
			return false;
		}

		// 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 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 1.0.0
			 * @since 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;
	}


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.