Users: allow -1
(no limit, use with extreme caution on large sites) as the value for number
in WP_User_Query
- similar to posts_per_page => -1
in WP_Query
.
Adds unit tests. Props mordauk, jesin, nofearinc. Fixes #28631. git-svn-id: https://develop.svn.wordpress.org/trunk@35114 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
455392c531
commit
4c0b89553a
@ -419,7 +419,7 @@ class WP_User_Query {
|
||||
$this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
|
||||
|
||||
// limit
|
||||
if ( isset( $qv['number'] ) && $qv['number'] ) {
|
||||
if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
|
||||
if ( $qv['offset'] ) {
|
||||
$this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
|
||||
} else {
|
||||
|
@ -434,6 +434,26 @@ class Tests_User_Query extends WP_UnitTestCase {
|
||||
$this->assertContains( "ORDER BY user_login DESC, user_email ASC", $q->query_orderby );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28631
|
||||
*/
|
||||
function test_number() {
|
||||
$user_ids = $this->factory->user->create_many( 10 );
|
||||
|
||||
$users = new WP_User_Query( array( 'blog_id' => get_current_blog_id() ) );
|
||||
$users = $users->get_results();
|
||||
|
||||
$this->assertEquals( 12, count( $users ) );
|
||||
|
||||
$users = new WP_User_Query( array( 'blog_id' => get_current_blog_id(), 'number' => 10 ) );
|
||||
$users = $users->get_results();
|
||||
$this->assertEquals( 10, count( $users ) );
|
||||
|
||||
$users = new WP_User_Query( array( 'blog_id' => get_current_blog_id(), 'number' => -1 ) );
|
||||
$users = $users->get_results();
|
||||
$this->assertEquals( 12, count( $users ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21119
|
||||
*/
|
||||
@ -469,6 +489,10 @@ class Tests_User_Query extends WP_UnitTestCase {
|
||||
|
||||
$query->prepare_query();
|
||||
$this->assertEquals( $_query_vars, $query->query_vars );
|
||||
|
||||
$query->prepare_query( array( 'number' => -1 ) );
|
||||
$this->assertNotEquals( 'LIMIT -1', $query->query_limit );
|
||||
$this->assertEmpty( $query->query_limit );
|
||||
}
|
||||
|
||||
public function test_meta_vars_should_be_converted_to_meta_query() {
|
||||
|
Loading…
Reference in New Issue
Block a user