Make WordPress Core

Ticket #41797: 41797.2.patch

File 41797.2.patch, 2.0 KB (added by birgire, 8 years ago)

Removed @access and combined the patch into a single file.

  • src/wp-includes/class-wp-user-query.php

     
    4040         */
    4141        private $total_users = 0;
    4242
     43        /**
     44         * The number of pages.
     45         *
     46         * @since 4.9.0
     47         * @var int
     48         */
     49        public $max_num_pages = 0;
     50
    4351        /**
    4452         * Metadata query container.
    4553         *
     
    608616                if ( isset( $qv['count_total'] ) && $qv['count_total'] )
    609617                        $this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
    610618
     619                if( $this->total_users && isset( $qv['number'] ) && $qv['number'] > 0 ) {
     620                        $this->max_num_pages = ceil( $this->total_users / $qv['number'] );
     621                }
     622
    611623                if ( !$this->results )
    612624                        return;
    613625
  • tests/phpunit/tests/user/query.php

     
    14341434                /* must not include user that has same string in other fields */
    14351435                $this->assertEquals( array(), $ids );
    14361436        }
     1437
     1438        /**
     1439         * @ticket 41797
     1440         */
     1441        public function test_max_num_pages() {
     1442
     1443                $q = new WP_User_Query( array(
     1444                        'role'          => 'author',
     1445                        'number'        => 3,
     1446                ) );
     1447
     1448                $this->assertEquals( 4, $q->get_total() );
     1449                $this->assertEquals( 2, $q->max_num_pages );
     1450        }
     1451
     1452        /**
     1453         * @ticket 41797
     1454         */
     1455        public function test_max_num_pages_should_be_zero_for_count_total_false_and_number_positive() {
     1456
     1457                $q = new WP_User_Query( array(
     1458                        'count_total'   => false,
     1459                        'number'        => 1,
     1460       
     1461                ) );
     1462
     1463                $this->assertEquals( 0, $q->max_num_pages );
     1464        }
     1465
     1466        /**
     1467         * @ticket 41797
     1468         */
     1469        public function test_max_num_pages_should_be_zero_for_count_total_true_and_no_number_set() {
     1470
     1471                $q = new WP_User_Query( array(
     1472                        'count_total'   => true,
     1473                ) );
     1474
     1475                $this->assertEquals( 0, $q->max_num_pages );
     1476        }
     1477
     1478
     1479
    14371480}