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

6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
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

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.