Make WordPress Core

Changeset 35114


Ignore:
Timestamp:
10/13/2015 02:39:05 AM (9 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-user-query.php

    r35101 r35114  
    420420
    421421        // limit
    422         if ( isset( $qv['number'] ) && $qv['number'] ) {
     422        if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
    423423            if ( $qv['offset'] ) {
    424424                $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
  • trunk/tests/phpunit/tests/user/query.php

    r35101 r35114  
    436436
    437437    /**
     438     * @ticket 28631
     439     */
     440    function test_number() {
     441        $user_ids = $this->factory->user->create_many( 10 );
     442
     443        $users = new WP_User_Query( array( 'blog_id' => get_current_blog_id() ) );
     444        $users = $users->get_results();
     445
     446        $this->assertEquals( 12, count( $users ) );
     447
     448        $users = new WP_User_Query( array( 'blog_id' => get_current_blog_id(), 'number' => 10 ) );
     449        $users = $users->get_results();
     450        $this->assertEquals( 10, count( $users ) );
     451
     452        $users = new WP_User_Query( array( 'blog_id' => get_current_blog_id(), 'number' => -1 ) );
     453        $users = $users->get_results();
     454        $this->assertEquals( 12, count( $users ) );
     455    }
     456
     457    /**
    438458     * @ticket 21119
    439459     */
     
    470490        $query->prepare_query();
    471491        $this->assertEquals( $_query_vars, $query->query_vars );
     492
     493        $query->prepare_query( array( 'number' => -1 ) );
     494        $this->assertNotEquals( 'LIMIT -1', $query->query_limit );
     495        $this->assertEmpty( $query->query_limit );
    472496    }
    473497
Note: See TracChangeset for help on using the changeset viewer.