bp_groups_filter_media_scope( array $retval = array(), array $filter = array() )

Set up media arguments for use with the ‘groups’ scope.

Description

Parameters

$retval

(Optional) Empty array by default.

Default value: array()

$filter

(Optional) Current activity arguments.

Default value: array()

Return

(array)

Source

File: bp-groups/bp-groups-filters.php

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
function bp_groups_filter_media_scope( $retval = array(), $filter = array() ) {
 
    // Determine the user_id.
    if ( ! empty( $filter['user_id'] ) ) {
        $user_id = $filter['user_id'];
    } else {
        $user_id = bp_displayed_user_id()
            ? bp_displayed_user_id()
            : bp_loggedin_user_id();
    }
 
    if ( 'groups' !== $filter['scope'] ) {
        // Fetch public groups.
        $public_groups = groups_get_groups( array(
            'fields'   => 'ids',
            'status'   => 'public',
            'per_page' => - 1,
        ) );
    }
    if ( ! empty( $public_groups['groups'] ) ) {
        $public_groups = $public_groups['groups'];
    } else {
        $public_groups = array();
    }
 
    // Determine groups of user.
    $groups = groups_get_user_groups( $user_id );
    if ( ! empty( $groups['groups'] ) ) {
        $groups = $groups['groups'];
    } else {
        $groups = array();
    }
 
    $group_ids = false;
    if ( ! empty( $groups ) && ! empty( $public_groups ) ) {
        $group_ids = array( 'groups' => array_unique( array_merge( $groups, $public_groups ) ) );
    } elseif ( empty( $groups ) && ! empty( $public_groups ) ) {
        $group_ids = array( 'groups' => $public_groups );
    } elseif ( ! empty( $groups ) && empty( $public_groups ) ) {
        $group_ids = array( 'groups' => $groups );
    }
 
    if ( empty( $group_ids ) ) {
        $group_ids = array( 'groups' => 0 );
    }
 
    $args = array(
        'relation' => 'AND',
        array(
            'column'  => 'group_id',
            'compare' => 'IN',
            'value'   => (array) $group_ids['groups'],
        ),
        array(
            'column' => 'privacy',
            'value'  => 'grouponly',
        ),
    );
 
    if ( ! bp_is_group_albums_support_enabled() ) {
        $args[] = array(
            'column'  => 'album_id',
            'compare' => '=',
            'value'   => '0',
        );
    }
 
    if ( ! empty( $filter['search_terms'] ) ) {
        $args[] = array(
            'column'  => 'title',
            'compare' => 'LIKE',
            'value'   => $filter['search_terms'],
        );
    }
 
    $retval = array(
        'relation' => 'OR',
        $args
    );
 
    return $retval;
}

Changelog

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