Ticket #41797: 41797.2.patch
| File 41797.2.patch, 2.0 KB (added by , 8 years ago) |
|---|
-
src/wp-includes/class-wp-user-query.php
40 40 */ 41 41 private $total_users = 0; 42 42 43 /** 44 * The number of pages. 45 * 46 * @since 4.9.0 47 * @var int 48 */ 49 public $max_num_pages = 0; 50 43 51 /** 44 52 * Metadata query container. 45 53 * … … 608 616 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) 609 617 $this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 610 618 619 if( $this->total_users && isset( $qv['number'] ) && $qv['number'] > 0 ) { 620 $this->max_num_pages = ceil( $this->total_users / $qv['number'] ); 621 } 622 611 623 if ( !$this->results ) 612 624 return; 613 625 -
tests/phpunit/tests/user/query.php
1434 1434 /* must not include user that has same string in other fields */ 1435 1435 $this->assertEquals( array(), $ids ); 1436 1436 } 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 1437 1480 }