Make WordPress Core

Changeset 21995


Ignore:
Timestamp:
09/25/2012 05:01:59 AM (12 years ago)
Author:
nacin
Message:

Add get() and set() methods to WP_User_Query for modifying query variables the way you might with WP_Query. props wonderboymusic. fixes #21426.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r21911 r21995  
    313313 */
    314314class WP_User_Query {
     315
     316    /**
     317     * Query vars, after parsing
     318     *
     319     * @since 3.5.0
     320     * @access public
     321     * @var array
     322     */
     323    var $query_vars = array();
    315324
    316325    /**
     
    382391        global $wpdb;
    383392
    384         $qv = &$this->query_vars;
     393        $qv =& $this->query_vars;
    385394
    386395        if ( is_array( $qv['fields'] ) ) {
     
    397406        }
    398407
    399         if ( $this->query_vars['count_total'] )
     408        if ( $qv['count_total'] )
    400409            $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
    401410
     
    529538        global $wpdb;
    530539
    531         if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) {
     540        $qv =& $this->query_vars;
     541
     542        if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
    532543            $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
    533544        } else {
     
    535546        }
    536547
    537         if ( $this->query_vars['count_total'] )
     548        if ( $qv['count_total'] )
    538549            $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
    539550
     
    541552            return;
    542553
    543         if ( 'all_with_meta' == $this->query_vars['fields'] ) {
     554        if ( 'all_with_meta' == $qv['fields'] ) {
    544555            cache_users( $this->results );
    545556
    546557            $r = array();
    547558            foreach ( $this->results as $userid )
    548                 $r[ $userid ] = new WP_User( $userid, '', $this->query_vars['blog_id'] );
     559                $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] );
    549560
    550561            $this->results = $r;
    551562        }
     563    }
     564
     565    /**
     566     * Retrieve query variable.
     567     *
     568     * @since 3.5.0
     569     * @access public
     570     *
     571     * @param string $query_var Query variable key.
     572     * @return mixed
     573     */
     574    function get( $query_var ) {
     575        if ( isset( $this->query_vars[$query_var] ) )
     576            return $this->query_vars[$query_var];
     577
     578        return null;
     579    }
     580
     581    /**
     582     * Set query variable.
     583     *
     584     * @since 3.5.0
     585     * @access public
     586     *
     587     * @param string $query_var Query variable key.
     588     * @param mixed $value Query variable value.
     589     */
     590    function set( $query_var, $value ) {
     591        $this->query_vars[$query_var] = $value;
    552592    }
    553593
Note: See TracChangeset for help on using the changeset viewer.