WordPress.org

Make WordPress Core

Changeset 16974


Ignore:
Timestamp:
12/15/10 23:56:53 (3 years ago)
Author:
scribu
Message:

Fetch only the required field in wp_dropdown_users(). See #14572

File:
1 edited

Legend:

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

    r16956 r16974  
    352352    var $total_users = 0; 
    353353 
    354     // SQL pieces 
     354    // SQL clauses 
     355    var $query_fields; 
    355356    var $query_from; 
    356357    var $query_where; 
     
    407408        $qv = &$this->query_vars; 
    408409 
    409         $this->query_from = " FROM $wpdb->users"; 
    410         $this->query_where = " WHERE 1=1"; 
     410        if ( is_array( $qv['fields'] ) ) { 
     411            $qv['fields'] = array_unique( $qv['fields'] ); 
     412 
     413            $this->query_fields = array(); 
     414            foreach ( $qv['fields'] as $field ) 
     415                $this->query_fields[] = $wpdb->users . '.' . esc_sql( $field ); 
     416            $this->query_fields = implode( ',', $this->query_fields ); 
     417        } else { 
     418            $this->query_fields = "$wpdb->users.ID"; 
     419        } 
     420 
     421        $this->query_from = "FROM $wpdb->users"; 
     422        $this->query_where = "WHERE 1=1"; 
    411423 
    412424        // sorting 
     
    438450        else 
    439451            $order = 'DESC'; 
    440         $this->query_orderby = " ORDER BY $orderby $order"; 
     452        $this->query_orderby = "ORDER BY $orderby $order"; 
    441453 
    442454        // limit 
    443455        if ( $qv['number'] ) { 
    444456            if ( $qv['offset'] ) 
    445                 $this->query_limit = $wpdb->prepare(" LIMIT %d, %d", $qv['offset'], $qv['number']); 
     457                $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); 
    446458            else 
    447                 $this->query_limit = $wpdb->prepare(" LIMIT %d", $qv['number']); 
     459                $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']); 
    448460        } 
    449461 
     
    511523        global $wpdb; 
    512524 
    513         $this->results = $wpdb->get_col("SELECT $wpdb->users.ID" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit); 
     525        if ( is_array( $this->query_vars['fields'] ) ) { 
     526            $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); 
     527        } else { 
     528            $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); 
     529        } 
    514530 
    515531        if ( !$this->results ) 
     
    517533 
    518534        if ( $this->query_vars['count_total'] ) 
    519             $this->total_users = $wpdb->get_var("SELECT COUNT($wpdb->users.ID)" . $this->query_from . $this->query_where); 
     535            $this->total_users = $wpdb->get_var("SELECT COUNT($wpdb->users.ID) $this->query_from $this->query_where $this->query_orderby $this->query_limit"); 
    520536 
    521537        if ( 'all' == $this->query_vars['fields'] ) { 
     
    968984    extract( $r, EXTR_SKIP ); 
    969985 
    970     $users = get_users( wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) ) ); 
     986    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) ); 
     987    $query_args['fields'] = array( 'ID', $show ); 
     988 
     989    $users = get_users( $query_args ); 
    971990 
    972991    $output = ''; 
Note: See TracChangeset for help on using the changeset viewer.