Skip to:
Content

BuddyPress.org

Changeset 9051


Ignore:
Timestamp:
09/27/2014 09:11:26 PM (10 years ago)
Author:
imath
Message:

When using BP_User_Query with meta_key and meta_value arguments, make sure no results are displayed if no user match the meta arguments.

Fixes #5904

Location:
trunk
Files:
2 edited

Legend:

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

    r9009 r9051  
    404404            if ( ! empty( $found_user_ids ) ) {
    405405                $sql['where'][] = "u.{$this->uid_name} IN (" . implode( ',', wp_parse_id_list( $found_user_ids ) ) . ")";
     406            } else {
     407                $sql['where'][] = '1 = 0';
    406408            }
    407409        }
     
    15471549     */
    15481550    public function __destruct() {
    1549         remove_filter( 'date_query_valid_columns', array( $this, 'register_date_column' ) );   
     1551        remove_filter( 'date_query_valid_columns', array( $this, 'register_date_column' ) );
    15501552    }
    15511553
  • trunk/tests/phpunit/testcases/core/class-bp-user-query.php

    r8958 r9051  
    368368    }
    369369
     370    /**
     371     * @group meta
     372     * @group BP5904
     373     */
     374    public function test_bp_user_query_with_user_meta_argument() {
     375        $u1 = $this->create_user();
     376        $u2 = $this->create_user();
     377
     378        bp_update_user_meta( $u2, 'foo', 'bar' );
     379
     380        $q = new BP_User_Query( array(
     381            'meta_key'        => 'foo',
     382            'meta_value'      => 'bar',
     383        ) );
     384
     385        $found_user_ids = array_values( wp_parse_id_list( wp_list_pluck( $q->results, 'ID' ) ) );
     386
     387        // Do a assertNotContains because there are weird issues with user #1 as created by WP
     388        $this->assertNotContains( $u1, $found_user_ids );
     389        $this->assertEquals( array( $u2 ), $found_user_ids );
     390    }
     391
     392    /**
     393     * @group meta
     394     * @group BP5904
     395     */
     396    public function test_bp_user_query_with_user_meta_argument_no_user() {
     397        $u1 = $this->create_user();
     398        $u2 = $this->create_user();
     399
     400        $q = new BP_User_Query( array(
     401            'meta_key'        => 'foo',
     402            'meta_value'      => 'bar',
     403        ) );
     404
     405        $found_user_ids = array_values( wp_parse_id_list( wp_list_pluck( $q->results, 'ID' ) ) );
     406
     407        $this->assertEmpty( $found_user_ids );
     408    }
     409
    370410}
Note: See TracChangeset for help on using the changeset viewer.