Make WordPress Core

Ticket #14572: fields.14572.diff

File fields.14572.diff, 2.2 KB (added by scribu, 13 years ago)
  • wp-includes/user.php

     
    351351         */
    352352        var $total_users = 0;
    353353
    354         // SQL pieces
     354        // SQL clauses
     355        var $query_fields;
    355356        var $query_from;
    356357        var $query_where;
    357358        var $query_orderby;
     
    406407
    407408                $qv = &$this->query_vars;
    408409
     410                if ( is_array( $qv['fields'] ) ) {
     411                        $this->query_fields = array();
     412                        foreach ( $qv['fields'] as $field )
     413                                $this->query_fields[] = $wpdb->users . '.' . esc_sql( $field );
     414                        $this->query_fields = implode( ',', $this->query_fields );
     415                } else {
     416                        $this->query_fields = "$wpdb->users.ID";
     417                }
    409418                $this->query_from = " FROM $wpdb->users";
    410419                $this->query_where = " WHERE 1=1";
    411420
     
    508517        function query() {
    509518                global $wpdb;
    510519
    511                 $this->results = $wpdb->get_col("SELECT $wpdb->users.ID" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit);
     520                if ( is_array( $this->query_vars['fields'] ) ) {
     521                        $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
     522                } else {
     523                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
     524                }
    512525
    513526                if ( !$this->results )
    514527                        return;
    515528
    516529                if ( $this->query_vars['count_total'] )
    517                         $this->total_users = $wpdb->get_var("SELECT COUNT($wpdb->users.ID)" . $this->query_from . $this->query_where);
     530                        $this->total_users = $wpdb->get_var("SELECT COUNT($wpdb->users.ID) $this->query_from $this->query_where $this->query_orderby $this->query_limit");
    518531
    519532                if ( 'all' == $this->query_vars['fields'] ) {
    520533                        cache_users($this->results);
     
    965978        $r = wp_parse_args( $args, $defaults );
    966979        extract( $r, EXTR_SKIP );
    967980
    968         $users = get_users( wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) ) );
     981        $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) );
     982        $query_args['fields'] = array( 'ID', $show );
    969983
     984        $users = get_users( $query_args );
     985
    970986        $output = '';
    971987        if ( !empty($users) ) {
    972988                $name = esc_attr( $name );