bp_get_new_group_invite_friend_list( array $args = array() )
Return a list of friends who can be invited to a group
Description
Parameters
- $args
-
(Optional) Array of arguments for friends list output.
Default value: array()
Return
(false|string) HTML list of checkboxes, or false
Source
File: bp-groups/bp-groups-template.php
function bp_get_new_group_invite_friend_list( $args = array() ) {
// Bail if no friends component.
if ( ! bp_is_active( 'friends' ) ) {
return false;
}
// Parse arguments.
$r = bp_parse_args( $args, array(
'user_id' => bp_loggedin_user_id(),
'group_id' => false,
'before' => '',
'separator' => 'li',
'after' => '',
), 'group_invite_friend_list' );
// No group passed, so look for new or current group ID's.
if ( empty( $r['group_id'] ) ) {
$bp = buddypress();
$r['group_id'] = ! empty( $bp->groups->new_group_id )
? $bp->groups->new_group_id
: $bp->groups->current_group->id;
}
// Setup empty items array.
$items = array();
// Build list markup parent elements.
$before = '';
if ( ! empty( $r['before'] ) ) {
$before = $r['before'];
}
$after = '';
if ( ! empty( $r['after'] ) ) {
$after = $r['after'];
}
// Get user's friends who are not in this group already.
$friends = friends_get_friends_invite_list( $r['user_id'], $r['group_id'] );
if ( ! empty( $friends ) ) {
// Get already invited users.
$invites = groups_get_invites_for_group( $r['user_id'], $r['group_id'] );
for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) {
$checked = in_array( (int) $friends[ $i ]['id'], (array) $invites );
$items[] = '<' . $r['separator'] . '><label for="f-' . esc_attr( $friends[ $i ]['id'] ) . '"><input' . checked( $checked, true, false ) . ' type="checkbox" name="friends[]" id="f-' . esc_attr( $friends[ $i ]['id'] ) . '" value="' . esc_attr( $friends[ $i ]['id'] ) . '" /> ' . esc_html( $friends[ $i ]['full_name'] ) . '</label></' . $r['separator'] . '>';
}
}
/**
* Filters the array of friends who can be invited to a group.
*
* @since BuddyPress 2.4.0
*
* @param array $items Array of friends.
* @param array $r Parsed arguments from bp_get_new_group_invite_friend_list()
* @param array $args Unparsed arguments from bp_get_new_group_invite_friend_list()
*/
$invitable_friends = apply_filters( 'bp_get_new_group_invite_friend_list', $items, $r, $args );
if ( ! empty( $invitable_friends ) && is_array( $invitable_friends ) ) {
$retval = $before . implode( "\n", $invitable_friends ) . $after;
} else {
$retval = false;
}
return $retval;
}
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.