Skip to:
Content

BuddyPress.org

Ticket #5596: 5596.01.patch

File 5596.01.patch, 3.0 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                        $group = new stdClass;
     165
     166                        if ( bp_get_current_group_id() ) {
     167                                $group->group_id = bp_get_current_group_id();
     168                        } else {
     169                                $group->group_id = BP_Groups_Group::get_id_from_slug( $slug );
     170                        }
     171
     172                        $this->groups = array( $group );
    165173                } else {
    166174                        $this->groups = groups_get_groups( array(
    167175                                'type'              => $type,
     
    185193                        $this->group_count       = (int) $this->groups['total'];
    186194                        $this->groups            = $this->groups['groups'];
    187195                } else if ( 'single-group' == $type ) {
    188                         $this->single_group      = true;
    189                         $this->total_group_count = 1;
    190                         $this->group_count       = 1;
     196                        if ( empty( $group->group_id ) ) {
     197                                $this->total_group_count = 0;
     198                                $this->group_count       = 0;
     199                        } else {
     200                                $this->total_group_count = 1;
     201                                $this->group_count       = 1;
     202                        }
    191203                } else {
    192204                        if ( empty( $max ) || $max >= (int) $this->groups['total'] ) {
    193205                                $this->total_group_count = (int) $this->groups['total'];
     
    260272                $this->in_the_loop = true;
    261273                $this->group       = $this->next_group();
    262274
    263                 if ( $this->single_group )
    264                         $this->group = groups_get_current_group();
     275                if ( $this->single_group ) {
     276                        if ( groups_get_current_group() ) {
     277                                $this->group = groups_get_current_group();
     278                        } else {
     279                                $this->group = groups_get_group( array( 'group_id' => $this->group->group_id ) );
     280                        }
     281                }
    265282
    266283                if ( 0 == $this->current_group ) // loop has just started
    267284                        do_action('group_loop_start');
  • 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, 'group_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() {