bp_ps_search( $request,  $users = null )

Returns BuddyBoss Profile Search results.

Description

Source

File: bp-core/profile-search/bps-search.php

318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
function bp_ps_search ( $request, $users = null ) {
    $results = array ( 'users' => array ( 0 ), 'validated' => true );
 
    $fields = bp_ps_parse_request( $request );
 
    $copied_arr = array();
 
    foreach ( $fields as $f ) {
        if ( !isset( $f->filter ) )
            continue;
        if ( !is_callable( $f->search ) )
            continue;
 
        $f = apply_filters( 'bp_ps_field_before_query', $f );
 
        $found = call_user_func( $f->search, $f );
        $found = apply_filters( 'bp_ps_field_search_results', $found, $f );
 
        $copied_arr = $found;
        if ( isset( $copied_arr ) && !empty( $copied_arr ) ) {
            foreach ( $copied_arr as $key => $user ) {
                $field_visibility = xprofile_get_field_visibility_level( intval( $f->id ), intval( $user ) );
                if ( 'adminsonly' === $field_visibility && ! current_user_can( 'administrator' ) ) {
                    if ( ( $key = array_search( $user, $found ) ) !== false ) {
                        unset( $found[ $key ] );
                    }
                }
                if ( 'friends' === $field_visibility && ! current_user_can( 'administrator' ) && false === friends_check_friendship( intval( $user ), bp_loggedin_user_id() ) ) {
                    if ( ( $key = array_search( $user, $found ) ) !== false ) {
                        unset( $found[ $key ] );
                    }
                }
            }
        }
 
        $match_all = apply_filters( 'bp_ps_match_all', true );
        if ( $match_all ) {
            $users = isset( $users ) ? array_intersect( $users, $found ) : $found;
            if ( count( $users ) == 0 )
                return $results;
        }
        else {
            $users = isset( $users ) ? array_merge( $users, $found ) : $found;
        }
    }
 
    if ( isset( $users ) )
        $results[ 'users' ] = $users;
    else
        $results[ 'validated' ] = false;
 
    return $results;
}

Changelog

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