Make WordPress Core

Ticket #21119: 21119.2.diff

File 21119.2.diff, 2.2 KB (added by wonderboymusic, 11 years ago)
  • src/wp-includes/user.php

     
    431431         * @return WP_User_Query
    432432         */
    433433        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 ) ) {
    435451                        $this->query_vars = wp_parse_args( $query, array(
    436452                                'blog_id' => $GLOBALS['blog_id'],
    437453                                'role' => '',
     
    450466                                'fields' => 'all',
    451467                                'who' => ''
    452468                        ) );
    453 
    454                         $this->prepare_query();
    455                         $this->query();
    456469                }
    457         }
    458470
    459         /**
    460          * Prepare the query variables
    461          *
    462          * @since 3.1.0
    463          * @access private
    464          */
    465         function prepare_query() {
    466                 global $wpdb;
    467 
    468471                $qv =& $this->query_vars;
    469472
    470473                if ( is_array( $qv['fields'] ) ) {
     
    649652         * Execute the query, with the current variables
    650653         *
    651654         * @since 3.1.0
    652          * @access private
    653655         */
    654656        function query() {
    655657                global $wpdb;
    656658
    657659                $qv =& $this->query_vars;
    658660
     661                $query = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
     662
    659663                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");
     664                        $this->results = $wpdb->get_results( $query );
    661665                } else {
    662                         $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
     666                        $this->results = $wpdb->get_col( $query );
    663667                }
    664668
    665669                /**
  • tests/phpunit/tests/user/query.php

     
    4343
    4444                $ids = $users->get_results();
    4545                $this->assertEquals( array( $this->user_id ), $ids );
    46 
    4746        }
    4847
    4948        function test_exclude() {