groups_check_has_invite_from_user( int $user_id, int $group_id, string $inviter_id = false, string $type = 'sent' )

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

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.

$inviter_id

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

Default value: false

$type

(string) (Optional) Specify a user ID to limit to only invited from that user. Default: 'false'.

Default value: 'sent'

Return

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

Source

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

function groups_check_has_invite_from_user( $user_id, $group_id, $inviter_id = false, $type = 'sent' ) {
	if ( empty( $user_id ) || empty( $group_id ) ) {
		return false;
	}

	$args = array(
		'user_id'     => $user_id,
		'item_id'     => $group_id,
		'invite_sent' => 'sent',
	);
	if ( $inviter_id ) {
		$args['inviter_id'] = $inviter_id;
	}
	if ( $type === 'draft' || $type === 'all' ) {
		$args['invite_sent'] = $type;
	}

	$invites_class = new BP_Groups_Invitation_Manager();

	return $invites_class->invitation_exists( $args );
}

Changelog

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