Skip to:
Content

BuddyPress.org

Changeset 8329


Ignore:
Timestamp:
04/28/2014 11:24:06 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Backwards compatibility for querying single groups via the slug argument. Props r-a-y. Fixes #5596. (trunk)

Location:
trunk
Files:
2 edited

Legend:

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

    r8244 r8329  
    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(
     
    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'] ) {
     
    260284        $this->in_the_loop = true;
    261285        $this->group       = $this->next_group();
    262 
    263         if ( $this->single_group )
    264             $this->group = groups_get_current_group();
    265286
    266287        if ( 0 == $this->current_group ) // loop has just started
  • trunk/tests/testcases/groups/template.php

    r8069 r8329  
    9797        $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) );
    9898        $this->assertEquals( array( $g1, $g3, $g2, ), $ids );
     99    }
     100
     101    /**
     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 );
    99126    }
    100127
Note: See TracChangeset for help on using the changeset viewer.