Skip to:
Content

BuddyPress.org

Changeset 11046


Ignore:
Timestamp:
08/30/2016 06:44:51 PM (3 years ago)
Author:
dcavins
Message:

Return active types only in bp_groups_get_group_type().

When compiling the array of types for the group in
bp_groups_get_group_type(), only include those types that are
currently registered.

Fixes #7224.

Location:
trunk
Files:
2 edited

Legend:

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

    r11032 r11046  
    22962296
    22972297    if ( false === $types ) {
    2298         $types = bp_get_object_terms( $group_id, 'bp_group_type' );
    2299 
    2300         if ( ! is_wp_error( $types ) ) {
    2301             $types = wp_list_pluck( $types, 'name' );
     2298        $raw_types = bp_get_object_terms( $group_id, 'bp_group_type' );
     2299
     2300        if ( ! is_wp_error( $raw_types ) ) {
     2301            $types = array();
     2302
     2303            // Only include currently registered group types.
     2304            foreach ( $raw_types as $gtype ) {
     2305                if ( bp_groups_get_group_type_object( $gtype->name ) ) {
     2306                    $types[] = $gtype->name;
     2307                }
     2308            }
     2309
    23022310            wp_cache_set( $group_id, $types, 'bp_groups_group_type' );
    23032311        }
  • trunk/tests/phpunit/testcases/groups/types.php

    r10773 r11046  
    252252        $this->assertEqualSets( array( 'bar' ), $types );
    253253    }
     254
     255    public function test_groups_get_type_should_not_return_unregistered_types() {
     256        $g = $this->factory->group->create( array( 'creator_id' => self::$u1 ) );
     257        bp_groups_register_group_type( 'foo' );
     258        bp_groups_set_group_type( $g, 'foo' );
     259
     260        // Directly set a type that hasn't been registered.
     261        bp_set_object_terms( $g, 'ugh', 'bp_group_type', true );
     262
     263        $type = bp_groups_get_group_type( $g, false );
     264        $this->assertEquals( array( 'foo' ), $type );
     265    }
    254266}
Note: See TracChangeset for help on using the changeset viewer.