Skip to:
Content

BuddyPress.org

Changeset 12744


Ignore:
Timestamp:
10/09/2020 01:25:47 PM (6 years ago)
Author:
dcavins
Message:

Support status parameter in bp_has_groups().

Allow a status parameter to be passed through bp_has_groups() to its underlying function, groups_has_groups().

Fixes #8310.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-template.php

    r12647 r12744  
    294294 * @since 2.6.0 Added `$group_type`, `$group_type__in`, and `$group_type__not_in` parameters.
    295295 * @since 2.7.0 Added `$update_admin_cache` parameter.
     296 * @since 7.0.0 Added `$status` parameter.
    296297 *
    297298 * @param array|string $args {
     
    320321 *     @type array|string $group_type__not_in Array or comma-separated list of group types that will be
    321322 *                                            excluded from results.
     323 *     @type array|string $status             Array or comma-separated list of group statuses to limit results to.
    322324 *     @type array        $meta_query         An array of meta_query conditions.
    323325 *                                            See {@link WP_Meta_Query::queries} for description.
     
    370372                        // Can be a comma-separated list.
    371373                        $group_type = explode( ',', $_GET['group_type'] );
     374                }
     375        }
     376
     377        $status = array();
     378        if ( ! empty( $_GET['status'] ) ) {
     379                if ( is_array( $_GET['status'] ) ) {
     380                        $status = $_GET['status'];
     381                } else {
     382                        // Can be a comma-separated list.
     383                        $status = explode( ',', $_GET['status'] );
    372384                }
    373385        }
     
    399411                'group_type__in'     => '',
    400412                'group_type__not_in' => '',
     413                'status'             => $status,
    401414                'meta_query'         => false,
    402415                'include'            => false,
     
    423436                'group_type__in'     => $r['group_type__in'],
    424437                'group_type__not_in' => $r['group_type__not_in'],
     438                'status'             => $r['status'],
    425439                'meta_query'         => $r['meta_query'],
    426440                'include'            => $r['include'],
  • trunk/src/bp-groups/classes/class-bp-groups-template.php

    r12426 r12744  
    172172                        'group_type__in'     => '',
    173173                        'group_type__not_in' => '',
     174                        'status'             => array(),
    174175                        'meta_query'         => false,
    175176                        'update_meta_cache'  => true,
     
    225226                                'group_type__in'     => $group_type__in,
    226227                                'group_type__not_in' => $group_type__not_in,
     228                                'status'             => $status,
    227229                                'include'            => $include,
    228230                                'exclude'            => $exclude,
  • trunk/tests/phpunit/testcases/groups/template.php

    r12516 r12744  
    116116                $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) );
    117117                $this->assertEquals( array( $g1 ), $ids );
     118
     119                $this->assertEquals( 1, $groups_template->group_count );
     120        }
     121
     122        /**
     123         * Test using the 'status' parameter in bp_has_groups()
     124         *
     125         * @group bp_has_groups
     126         */
     127        public function test_bp_has_groups_status() {
     128                $g1 = self::factory()->group->create( array(
     129                        'status' => 'public',
     130                ) );
     131                $g2 = self::factory()->group->create( array(
     132                        'status' => 'private',
     133                ) );
     134                $g3 = self::factory()->group->create( array(
     135                        'status' => 'hidden',
     136                ) );
     137
     138                global $groups_template;
     139                bp_has_groups( array(
     140                        'status' => 'private',
     141                ) );
     142
     143                $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) );
     144                $this->assertEqualSets( array( $g2 ), $ids );
    118145
    119146                $this->assertEquals( 1, $groups_template->group_count );
Note: See TracChangeset for help on using the changeset viewer.