BP_REST_Members_Endpoint::rest_bp_ps_search( array $request )

Returns BuddyBoss Profile Search results.

Description

Parameters

$request

(Required) Array of filter's data.

Return

(array)

Source

File: bp-members/classes/class-bp-rest-members-endpoint.php

1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
public function rest_bp_ps_search( $request ) {
    $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' ) ) {
                    $key = array_search( $user, $found, true );
                    if ( false !== $key ) {
                        unset( $found[ $key ] );
                    }
                }
                if ( 'friends' === $field_visibility && ! current_user_can( 'administrator' ) && false === friends_check_friendship( intval( $user ), get_current_user_id() ) ) {
                    $key = array_search( $user, $found, true );
                    if ( false !== $key ) {
                        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
0.1.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.