Ticket #21119: 21119.3.diff
File 21119.3.diff, 3.6 KB (added by , 11 years ago) |
---|
-
src/wp-includes/user.php
431 431 * @return WP_User_Query 432 432 */ 433 433 function __construct( $query = null ) { 434 if ( !empty( $query ) ) { 434 if ( ! empty( $query ) ) { 435 $this->prepare_query( $query ); 436 $this->query(); 437 } 438 } 439 440 /** 441 * Prepare the query variables 442 * 443 * @since 3.1.0 444 * 445 * @param string|array $args The query variables 446 */ 447 function prepare_query( $query = array() ) { 448 global $wpdb; 449 450 if ( empty( $this->query_vars ) || ! empty( $query ) ) { 451 $this->query_limit = null; 435 452 $this->query_vars = wp_parse_args( $query, array( 436 453 'blog_id' => $GLOBALS['blog_id'], 437 454 'role' => '', … … 450 467 'fields' => 'all', 451 468 'who' => '' 452 469 ) ); 453 454 $this->prepare_query();455 $this->query();456 470 } 457 }458 471 459 /**460 * Prepare the query variables461 *462 * @since 3.1.0463 * @access private464 */465 function prepare_query() {466 global $wpdb;467 468 472 $qv =& $this->query_vars; 469 473 470 474 if ( is_array( $qv['fields'] ) ) { … … 649 653 * Execute the query, with the current variables 650 654 * 651 655 * @since 3.1.0 652 * @access private653 656 */ 654 657 function query() { 655 658 global $wpdb; 656 659 657 660 $qv =& $this->query_vars; 658 661 662 $query = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; 663 659 664 if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { 660 $this->results = $wpdb->get_results( "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");665 $this->results = $wpdb->get_results( $query ); 661 666 } else { 662 $this->results = $wpdb->get_col( "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");667 $this->results = $wpdb->get_col( $query ); 663 668 } 664 669 665 670 /** -
tests/phpunit/tests/user/query.php
43 43 44 44 $ids = $users->get_results(); 45 45 $this->assertEquals( array( $this->user_id ), $ids ); 46 47 46 } 48 47 49 48 function test_exclude() { … … 101 100 102 101 $this->assertEquals( $names, $values ); 103 102 } 103 104 function test_prepare_query() { 105 $query = new WP_User_Query(); 106 $this->assertEmpty( $query->query_fields ); 107 $this->assertEmpty( $query->query_from ); 108 $this->assertEmpty( $query->query_limit ); 109 $this->assertEmpty( $query->query_orderby ); 110 $this->assertEmpty( $query->query_where ); 111 $this->assertEmpty( $query->query_vars ); 112 $_query_vars = $query->query_vars; 113 114 $query->prepare_query(); 115 $this->assertNotEmpty( $query->query_fields ); 116 $this->assertNotEmpty( $query->query_from ); 117 $this->assertEmpty( $query->query_limit ); 118 $this->assertNotEmpty( $query->query_orderby ); 119 $this->assertNotEmpty( $query->query_where ); 120 $this->assertNotEmpty( $query->query_vars ); 121 $this->assertNotEquals( $_query_vars, $query->query_vars ); 122 123 // All values get reset 124 $query->prepare_query( array( 'number' => 8 ) ); 125 $this->assertNotEmpty( $query->query_limit ); 126 $this->assertEquals( 'LIMIT 8', $query->query_limit ); 127 128 // All values get reset 129 $query->prepare_query( array( 'fields' => 'all' ) ); 130 $this->assertEmpty( $query->query_limit ); 131 $this->assertEquals( '', $query->query_limit ); 132 $_query_vars = $query->query_vars; 133 134 $query->prepare_query(); 135 $this->assertEquals( $_query_vars, $query->query_vars ); 136 } 104 137 }