Make WordPress Core

Ticket #21426: user-query-get-set.diff

File user-query-get-set.diff, 2.7 KB (added by wonderboymusic, 13 years ago)
  • wp-includes/user.php

     
    333333 * @since 3.1.0
    334334 */
    335335class WP_User_Query {
    336 
    337336        /**
     337         * Query vars, after parsing
     338         *
     339         * @since 3.5.0
     340         * @access public
     341         * @var array
     342         */
     343        var $query_vars = array();
     344       
     345        /**
    338346         * List of found user ids
    339347         *
    340348         * @since 3.1.0
     
    402410        function prepare_query() {
    403411                global $wpdb;
    404412
    405                 $qv = &$this->query_vars;
     413                $qv =& $this->query_vars;
    406414
    407415                if ( is_array( $qv['fields'] ) ) {
    408416                        $qv['fields'] = array_unique( $qv['fields'] );
     
    417425                        $this->query_fields = "$wpdb->users.ID";
    418426                }
    419427
    420                 if ( $this->query_vars['count_total'] )
     428                if ( $qv['count_total'] )
    421429                        $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
    422430
    423431                $this->query_from = "FROM $wpdb->users";
     
    549557        function query() {
    550558                global $wpdb;
    551559
    552                 if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) {
     560                $qv =& $this->query_vars;
     561               
     562                if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
    553563                        $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
    554564                } else {
    555565                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
    556566                }
    557567
    558                 if ( $this->query_vars['count_total'] )
     568                if ( $qv['count_total'] )
    559569                        $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
    560570
    561571                if ( !$this->results )
    562572                        return;
    563573
    564                 if ( 'all_with_meta' == $this->query_vars['fields'] ) {
     574                if ( 'all_with_meta' == $qv['fields'] ) {
    565575                        cache_users( $this->results );
    566576
    567577                        $r = array();
    568578                        foreach ( $this->results as $userid )
    569                                 $r[ $userid ] = new WP_User( $userid, '', $this->query_vars['blog_id'] );
     579                                $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] );
    570580
    571581                        $this->results = $r;
    572582                }
    573583        }
    574584
     585        /**
     586         * Retrieve query variable.
     587         *
     588         * @since 3.5.0
     589         * @access public
     590         *
     591         * @param string $query_var Query variable key.
     592         * @return mixed
     593         */
     594        function get( $query_var ) {
     595                if ( isset( $this->query_vars[$query_var] ) )
     596                        return $this->query_vars[$query_var];
     597
     598                return '';
     599        }
     600
     601        /**
     602         * Set query variable.
     603         *
     604         * @since 3.5.0
     605         * @access public
     606         *
     607         * @param string $query_var Query variable key.
     608         * @param mixed $value Query variable value.
     609         */
     610        function set( $query_var, $value ) {
     611                $this->query_vars[$query_var] = $value;
     612        }
     613       
    575614        /*
    576615         * Used internally to generate an SQL string for searching across multiple columns
    577616         *