groups_send_invites( array $args = array() )

Send all pending invites by a single user to a specific group.

Description

Parameters

$args

(array) (Optional) An array of optional arguments.

  • 'user_id'
    (int) ID of the invited user.
  • 'invitee_email'
    (string) Email address of the invited user, if not a member of the site.
  • 'group_id'
    (string) ID of the group or an array of group IDs.
  • 'inviter_id'
    (string) ID of the user extending the invitation.
  • 'force_resend'
    (bool) Whether to resend the email & notification if one has already been sent.

Default value: array()

Source

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

function groups_send_invites( $user_id, $group_id ) {

	if ( empty( $user_id ) )
		$user_id = bp_loggedin_user_id();

	// Send friend invites.
	$invited_users = groups_get_invites_for_group( $user_id, $group_id );
	$group = groups_get_group( $group_id );

	for ( $i = 0, $count = count( $invited_users ); $i < $count; ++$i ) {
		$member = new BP_Groups_Member( $invited_users[$i], $group_id );

		// Skip if we've already sent an invite to this user.
		if ( $member->invite_sent ) {
			continue;
		}

		// Send the actual invite.
		groups_notification_group_invites( $group, $member, $user_id );

		$member->invite_sent = 1;
		$member->save();
	}

	/**
	 * Fires after the sending of invites for a group.
	 *
	 * @since BuddyPress 1.0.0
	 * @since BuddyPress 2.5.0 Added $user_id to passed parameters.
	 *
	 * @param int   $group_id      ID of the group who's being invited to.
	 * @param array $invited_users Array of users being invited to the group.
	 * @param int   $user_id       ID of the inviting user.
	 */
	do_action( 'groups_send_invites', $group_id, $invited_users, $user_id );
}

Changelog

Changelog
Version Description
BuddyPress 5.0.0 Parameters changed to associative array. BuddyPress 5.0.0 Parameters changed to associative array.
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.