bp_dd_get_random_forums_ids( int $count = 1, string $output = 'array' )

Get the array (or a string) of forum IDs.

Description

Parameters

$count

(Optional) If you need all, use 0.

Default value: 1

$output

(Optional) What to return: 'array' or 'string'. If string - comma separated.

Default value: 'array'

Return

(array|string) Default is array.

Source

File: bp-core/bp-core-tools-default-data.php

423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
function bp_dd_get_random_forums_ids( $count = 1, $output = 'array' ) {
    $forums_arr = (array) bp_get_option( 'bp_dd_imported_forum_ids' );
 
    if ( ! empty( $forums_arr ) ) {
        $total_forums = count( $forums_arr );
        if ( $count <= 0 || $count > $total_forums ) {
            $count = $total_forums;
        }
 
        // Get random groups.
        $random_keys = (array) array_rand( $forums_arr, $count );
        $forums      = array();
        foreach ( $forums_arr as $key => $value ) {
            if ( in_array( $key, $random_keys ) ) {
                $forums[] = $value;
            }
        }
    }
 
    /*
     * Convert to integers, because get_col() returns array of strings.
     */
    $forums = array_map( 'intval', $forums );
 
    if ( $output === 'string' ) {
        return implode( ',', $forums );
    }
 
    return $forums;
}

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.