Ticket #14572: fields.14572.diff
File fields.14572.diff, 2.2 KB (added by , 13 years ago) |
---|
-
wp-includes/user.php
351 351 */ 352 352 var $total_users = 0; 353 353 354 // SQL pieces 354 // SQL clauses 355 var $query_fields; 355 356 var $query_from; 356 357 var $query_where; 357 358 var $query_orderby; … … 406 407 407 408 $qv = &$this->query_vars; 408 409 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 } 409 418 $this->query_from = " FROM $wpdb->users"; 410 419 $this->query_where = " WHERE 1=1"; 411 420 … … 508 517 function query() { 509 518 global $wpdb; 510 519 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 } 512 525 513 526 if ( !$this->results ) 514 527 return; 515 528 516 529 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"); 518 531 519 532 if ( 'all' == $this->query_vars['fields'] ) { 520 533 cache_users($this->results); … … 965 978 $r = wp_parse_args( $args, $defaults ); 966 979 extract( $r, EXTR_SKIP ); 967 980 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 ); 969 983 984 $users = get_users( $query_args ); 985 970 986 $output = ''; 971 987 if ( !empty($users) ) { 972 988 $name = esc_attr( $name );