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

Set up document 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

618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
function bp_groups_filter_document_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();
    }
 
    $folder_id = 0;
    $folders   = array();
    if ( ! empty( $filter['folder_id'] ) ) {
        $folder_id = (int) $filter['folder_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' => array() );
    }
 
    if ( bp_is_group() ) {
        $group_ids = array( 'groups' => array( bp_get_current_group_id() ) );
    }
 
    if ( ! empty( $filter['search_terms'] ) ) {
        if ( ! empty( $folder_id ) ) {
            $folder_ids       = array();
            $fetch_folder_ids = bp_document_get_folder_children( (int) $folder_id );
            if ( $fetch_folder_ids ) {
                foreach ( $fetch_folder_ids as $single_folder ) {
                    $single_folder_ids = bp_document_get_folder_children( (int) $single_folder );
                    if ( $single_folder_ids ) {
                        array_merge( $folder_ids, $single_folder_ids );
                    }
                    array_push( $folder_ids, $single_folder );
                }
            }
 
            $folder_ids[] = $folder_id;
            $folders      = array(
                'column'  => 'parent',
                'compare' => 'IN',
                'value'   => $folder_ids,
            );
        }
    } else {
        if ( ! empty( $folder_id ) ) {
            $folders = array(
                'column'  => 'folder_id',
                'compare' => '=',
                'value'   => $folder_id,
            );
        } else {
            $folders = array(
                'column' => 'folder_id',
                'value'  => 0,
            );
        }
    }
 
    if ( ! bp_is_group_document_support_enabled() ) {
        $group_ids['groups'] = array( 0 );
    }
 
    $args = array(
        'relation' => 'AND',
        array(
            'column'  => 'group_id',
            'compare' => 'IN',
            'value'   => (array) $group_ids['groups'],
        ),
        array(
            'column' => 'privacy',
            'value'  => 'grouponly',
        ),
        $folders,
    );
 
    return $args;
}

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.