bp_nouveau_prepare_group_potential_invites_for_js( $user )

Prepare list of group invites for JS.

Description

Source

File: bp-templates/bp-nouveau/includes/groups/functions.php

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
function bp_nouveau_prepare_group_potential_invites_for_js( $user ) {
    $bp = buddypress();
 
    $response = array(
        'id'           => intval( $user->ID ),
        'name'         => $user->display_name,
        'avatar'       => htmlspecialchars_decode( bp_core_fetch_avatar( array(
            'item_id' => $user->ID,
            'object'  => 'user',
            'type'    => 'thumb',
            'width'   => 50,
            'height'  => 50,
            'html'    => false )
        ) ),
    );
 
    // Group id
    $group_id = bp_get_current_group_id()?: (int) $_REQUEST['group_id'];
 
    // Do extra queries only if needed
    if ( ! empty( $bp->groups->invites_scope ) && 'invited' === $bp->groups->invites_scope ) {
        $response['is_sent']  = (bool) groups_check_user_has_invite( $user->ID, $group_id );
 
        $inviter_ids = bp_nouveau_groups_get_inviter_ids( $user->ID, $group_id );
 
        foreach ( $inviter_ids as $inviter_id ) {
            $class = false;
 
            if ( bp_loggedin_user_id() === (int) $inviter_id ) {
                $class = 'group-self-inviter';
            }
 
            $response['invited_by'][] = array(
                'avatar' => htmlspecialchars_decode( bp_core_fetch_avatar( array(
                    'item_id' => $inviter_id,
                    'object'  => 'user',
                    'type'    => 'thumb',
                    'width'   => 50,
                    'height'  => 50,
                    'html'    => false,
                    'class'   => $class,
                ) ) ),
                'user_link' => bp_core_get_userlink( $inviter_id, false, true ),
                'user_name' => bp_core_get_username( $inviter_id ),
            );
        }
 
        if ( bp_is_item_admin() ) {
            $response['can_edit'] = true;
        } else {
            $response['can_edit'] = in_array( bp_loggedin_user_id(), $inviter_ids );
        }
    }
 
    /**
     * Filters the response value for potential group invite data for use with javascript.
     *
     * @since BuddyPress 3.0.0
     *
     * @param array   $response Array of invite data.
     * @param WP_User $user User object.
     */
    return apply_filters( 'bp_nouveau_prepare_group_potential_invites_for_js', $response, $user );
}

Changelog

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