groups_send_invites( array $args )
Send some or all pending invites by a single user to a specific group.
Description Description
Parameters Parameters
- $args
-
(Required) 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.
- 'user_id'
Source Source
File: bp-groups/bp-groups-functions.php
function groups_send_invites( $args = array() ) {
// Backward compatibility with old method of passing arguments.
if ( ! is_array( $args ) || func_num_args() > 1 ) {
_deprecated_argument( __METHOD__, '5.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
$old_args_keys = array(
0 => 'inviter_id',
1 => 'group_id',
);
$args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
}
$r = bp_parse_args( $args, array(
'user_id' => false,
'invitee_email' => '',
'group_id' => 0,
'inviter_id' => bp_loggedin_user_id(),
'force_resend' => false,
), 'groups_send_invitation' );
$args = array(
'user_id' => $r['user_id'],
'invitee_email' => $r['invitee_email'],
'item_id' => $r['group_id'],
'inviter_id' => $r['inviter_id'],
);
/*
* We will generally only want to fetch unsent invitations.
* If force_resend is true, then we need to fetch both sent and draft invites.
*/
if ( $r['force_resend'] ) {
$args['invite_sent'] = 'all';
} else {
$args['invite_sent'] = 'draft';
}
$invites = groups_get_invites( $args );
$invited_users = array();
$invites_class = new BP_Groups_Invitation_Manager();
foreach ( $invites as $invite ) {
$invited_users[] = $invite->user_id;
$invites_class->send_invitation_by_id( $invite->id );
}
/**
* Fires after the sending of invites for a group.
*
* @since 1.0.0
* @since 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', $r['group_id'], $invited_users, $r['inviter_id'] );
}
Changelog Changelog
| Version | Description |
|---|---|
| 5.0.0 | Parameters changed to associative array. |
| 1.0.0 | Introduced. |