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

Notify a member they have been invited to a group.


Parameters Parameters

$group

(BP_Groups_Group) (Required) Group object.

$member

(BP_Groups_Member|int) (Required) Member object or invited_user_id.

$inviter_user_id

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


Source Source

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

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

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

	if ( $member instanceof BP_Groups_Member ) {
		$invited_user_id = $member->user_id;
	} else if ( is_int( $member ) ) {
		$invited_user_id = $member;
	}

	// 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',
	);

	$invite_message = '';
	$invitations = groups_get_invites( $args = array(
		'user_id'    => $invited_user_id,
		'item_id'    => $group->id,
		'inviter_id' => $inviter_user_id,
	) );
	if ( $invitations ) {
		$invite_message = current( $invitations )->content;
	}

	$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/' ),
			'invite.message' => $invite_message,
			'unsubscribe'    => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
		),
	);

	bp_send_email( 'groups-invitation', (int) $invited_user_id, $args );
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.