Skip to:
Content

BuddyPress.org

Ticket #7224: 7224.03.patch

File 7224.03.patch, 1.7 KB (added by dcavins, 8 years ago)

Remove the unneeded wp_list_pluck() since we're already looping through the array.

  • src/bp-groups/bp-groups-functions.php

    diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
    index cb0753e..93c089f 100644
    function bp_groups_get_group_type( $group_id, $single = true ) { 
    22942294        $types = wp_cache_get( $group_id, 'bp_groups_group_type' );
    22952295
    22962296        if ( false === $types ) {
    2297                 $types = bp_get_object_terms( $group_id, 'bp_group_type' );
     2297                $raw_types = bp_get_object_terms( $group_id, 'bp_group_type' );
     2298
     2299                if ( ! is_wp_error( $raw_types ) ) {
     2300                        $types = array();
     2301
     2302                        // Only include currently registered group types.
     2303                        foreach ( $raw_types as $gtype ) {
     2304                                if ( bp_groups_get_group_type_object( $gtype->name ) ) {
     2305                                        $types[] = $gtype->name;
     2306                                }
     2307                        }
    22982308
    2299                 if ( ! is_wp_error( $types ) ) {
    2300                         $types = wp_list_pluck( $types, 'name' );
    23012309                        wp_cache_set( $group_id, $types, 'bp_groups_group_type' );
    23022310                }
    23032311        }
  • tests/phpunit/testcases/groups/types.php

    diff --git tests/phpunit/testcases/groups/types.php tests/phpunit/testcases/groups/types.php
    index b0ee0d0..18e5ca6 100644
    class BP_Tests_Groups_Types extends BP_UnitTestCase { 
    251251
    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}