groups_check_user_has_invite( int $user_id, int $group_id, string $type = 'sent' )

Check to see whether a user has already been invited to a group.

Description

By default, the function checks for invitations that have been sent. Entering ‘all’ as the $type parameter will return unsent invitations as well (useful to make sure AJAX requests are not duplicated).

Parameters

$user_id

(int) (Required) ID of potential group member.

$group_id

(int) (Required) ID of potential group.

$type

(string) (Optional) Use 'sent' to check for sent invites, 'all' to check for all. Default: 'sent'.

Default value: 'sent'

Return

(int|bool) ID of the membership if found, otherwise false.

Source

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

function groups_check_user_has_invite( $user_id, $group_id, $type = 'sent' ) {
	$invite = false;

	$args = array(
		'is_confirmed' => false,
		'is_banned'    => null,
		'is_admin'     => null,
		'is_mod'       => null,
	);

	if ( 'sent' === $type ) {
		$args['invite_sent'] = true;
	}

	$user_groups = bp_get_user_groups( $user_id, $args );

	if ( isset( $user_groups[ $group_id ] ) && 0 !== $user_groups[ $group_id ]->inviter_id ) {
		$invite = $user_groups[ $group_id ]->id;
	}

	return $invite;
}

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.