Skip to:
Content

Changeset 8430


Ignore:
Timestamp:
05/19/2014 07:28:36 PM (4 years ago)
Author:
boonebgorges
Message:

Correct query concatenation for exclude_groups param in BP_XProfile_Group::get()

The previous format was not working properly when passing multiple group ids.

Fixes #5649

Props imath

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-classes.php

    r8347 r8430  
    151151        $where_sql = '';
    152152
    153         if ( !empty( $profile_group_id ) )
     153        if ( ! empty( $profile_group_id ) ) {
    154154            $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id );
    155         elseif ( $exclude_groups )
    156             $where_sql = $wpdb->prepare( "WHERE g.id NOT IN ({$exclude_groups})");
     155        } else if ( $exclude_groups ) {
     156            $exclude_groups = join( ',', wp_parse_id_list( $exclude_groups ) );
     157            $where_sql = "WHERE g.id NOT IN ({$exclude_groups})";
     158        }
    157159
    158160        if ( ! empty( $hide_empty_groups ) ) {
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php

    r7915 r8430  
    6868        $this->assertSame( $expected, $found );
    6969    }
     70
     71    /**
     72     * @group get_xprofile_groups
     73     */
     74    public function test_get_xprofile_groups() {
     75        $g1 = $this->factory->xprofile_group->create();
     76        $g2 = $this->factory->xprofile_group->create();
     77        $g3 = $this->factory->xprofile_group->create();
     78
     79        $all = BP_XProfile_Group::get();
     80        $all_results = array_map( 'absint', wp_list_pluck( $all, 'id' ) );
     81
     82        $e1 = array( $g1, $g2 );
     83        $groups1 = BP_XProfile_Group::get( array(
     84            'exclude_groups' => implode( ',', $e1 ),
     85        ) );
     86
     87        $r_groups1 = array_map( 'absint', wp_list_pluck( $groups1, 'id' ) );
     88        $found1 = array_diff( $all_results, $r_groups1 );
     89
     90        $this->assertSame( $e1, array_merge( $found1, array() ) );
     91
     92        $e2 = array( $g2, $g3 );
     93        $groups2 = BP_XProfile_Group::get( array(
     94            'exclude_groups' => $e2,
     95        ) );
     96
     97        $r_groups2 = array_map( 'absint', wp_list_pluck( $groups2, 'id' ) );
     98        $found2 = array_diff( $all_results, $r_groups2 );
     99
     100        $this->assertSame( $e2, array_merge( $found2, array() ) );
     101    }
    70102}
Note: See TracChangeset for help on using the changeset viewer.