Skip to:
Content

BuddyPress.org

Ticket #5596: 5596.02.patch

File 5596.02.patch, 3.2 KB (added by r-a-y, 12 years ago)
  • bp-groups/bp-groups-template.php

     
    159159                if ( 'invites' == $type ) {
    160160                        $this->groups = groups_get_invites_for_user( $user_id, $this->pag_num, $this->pag_page, $exclude );
    161161                } else if ( 'single-group' == $type ) {
    162                         $group           = new stdClass;
    163                         $group->group_id = bp_get_current_group_id();
    164                         $this->groups    = array( $group );
     162                        $this->single_group = true;
     163
     164                        if ( groups_get_current_group() ) {
     165                                $group = groups_get_current_group();
     166
     167                        } else {
     168                                $group = groups_get_group( array(
     169                                        'group_id'        => BP_Groups_Group::get_id_from_slug( $r['slug'] ),
     170                                        'populate_extras' => $r['populate_extras'],
     171                                ) );
     172                        }
     173
     174                        // backwards compatibility - the 'group_id' variable is not part of the
     175                        // BP_Groups_Group object, but we add it here for devs doing checks against it
     176                        //
     177                        // @see https://buddypress.trac.wordpress.org/changeset/3540
     178                        //
     179                        // this is subject to removal in a future release; devs should check against
     180                        // $group->id instead
     181                        $group->group_id = $group->id;
     182
     183                        $this->groups = array( $group );
     184
    165185                } else {
    166186                        $this->groups = groups_get_groups( array(
    167187                                'type'              => $type,
     
    185205                        $this->group_count       = (int) $this->groups['total'];
    186206                        $this->groups            = $this->groups['groups'];
    187207                } else if ( 'single-group' == $type ) {
    188                         $this->single_group      = true;
    189                         $this->total_group_count = 1;
    190                         $this->group_count       = 1;
     208                        if ( empty( $group->id ) ) {
     209                                $this->total_group_count = 0;
     210                                $this->group_count       = 0;
     211                        } else {
     212                                $this->total_group_count = 1;
     213                                $this->group_count       = 1;
     214                        }
    191215                } else {
    192216                        if ( empty( $max ) || $max >= (int) $this->groups['total'] ) {
    193217                                $this->total_group_count = (int) $this->groups['total'];
     
    260284                $this->in_the_loop = true;
    261285                $this->group       = $this->next_group();
    262286
    263                 if ( $this->single_group )
    264                         $this->group = groups_get_current_group();
    265 
    266287                if ( 0 == $this->current_group ) // loop has just started
    267288                        do_action('group_loop_start');
    268289        }
  • tests/testcases/groups/template.php

     
    9999        }
    100100
    101101        /**
     102         * Test using the 'slug' parameter in bp_has_groups()
     103         *
     104         * Note: The 'slug' parameter currently also requires the 'type' to be set
     105         * to 'single-group'.
     106         *
     107         * @group bp_has_groups
     108         */
     109        public function test_bp_has_groups_single_group_with_slug() {
     110                $g1 = $this->factory->group->create( array(
     111                        'name' => 'Test Group',
     112                        'slug' => 'test-group',
     113                        'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 100 ),
     114                ) );
     115
     116                global $groups_template;
     117                bp_has_groups( array(
     118                        'type' => 'single-group',
     119                        'slug' => 'test-group',
     120                ) );
     121
     122                $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) );
     123                $this->assertEquals( array( $g1 ), $ids );
     124
     125                $this->assertEquals( 1, $groups_template->group_count );
     126        }
     127
     128        /**
    102129         * @group bp_group_has_members
    103130         */
    104131        public function test_bp_group_has_members_vanilla() {