groups_notification_group_invites( BP_Groups_Group $group, BP_Groups_Member $member, int $inviter_user_id )

Notify a member they have been invited to a group.

Description

Parameters

$group

(Required) Group object.

$member

(Required) Member object.

$inviter_user_id

(Required) ID of the user who sent the invite.

Source

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

function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {

	// Bail if member has already been invited.
	if ( ! empty( $member->invite_sent ) ) {
		return;
	}

	// @todo $inviter_ud may be used for caching, test without it
	$inviter_ud      = bp_core_get_core_userdata( $inviter_user_id );
	$invited_user_id = $member->user_id;

	// Trigger a BuddyPress Notification.
	if ( bp_is_active( 'notifications' ) ) {
		bp_notifications_add_notification( array(
			'user_id'          => $invited_user_id,
			'item_id'          => $group->id,
			'component_name'   => buddypress()->groups->id,
			'component_action' => 'group_invite',
		) );
	}

	// Bail if member opted out of receiving this email.
	if ( 'no' === bp_get_user_meta( $invited_user_id, 'notification_groups_invite', true ) ) {
		return;
	}

	$invited_link = bp_core_get_user_domain( $invited_user_id ) . bp_get_groups_slug();

	$unsubscribe_args = array(
		'user_id'           => $invited_user_id,
		'notification_type' => 'groups-invitation',
	);

	$args         = array(
		'tokens' => array(
			'group'           => $group,
			'group.url'       => bp_get_group_permalink( $group ),
			'group.name'      => $group->name,
			'inviter.name'    => bp_core_get_userlink( $inviter_user_id, true, false, true ),
			'inviter.url'     => bp_core_get_user_domain( $inviter_user_id ),
			'inviter.id'      => $inviter_user_id,
			'invites.url'     => esc_url( $invited_link . '/invites/' ),
			'invites.message' => bp_groups_get_invite_messsage_for_user( $invited_user_id, $group->id ),
			'unsubscribe'     => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
		),
	);
	bp_send_email( 'groups-invitation', (int) $invited_user_id, $args );
}

Changelog

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