From 426a33b134a5c498b99fc58815a5824160999039 Mon Sep 17 00:00:00 2001 From: nacin Date: Sat, 13 Feb 2010 20:12:08 +0000 Subject: [PATCH] Don't query against entire users table in wp_dropdown_users() to be multisite friendly. Fixes #11086 git-svn-id: http://svn.automattic.com/wordpress/trunk@13122 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 4609f0eaf3..02f2abcbad 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -507,6 +507,7 @@ function setup_userdata($for_user_id = '') { *
  • selected - Which User ID is selected.
  • *
  • name - Default is 'user'. Name attribute of select element.
  • *
  • class - Class attribute of select element.
  • + *
  • blog - ID of blog (Multisite only). Defaults to ID of current blog.
  • * * * @since 2.3.0 @@ -516,13 +517,13 @@ function setup_userdata($for_user_id = '') { * @return string|null Null on display. String of HTML content on retrieve. */ function wp_dropdown_users( $args = '' ) { - global $wpdb; + global $wpdb, $blog_id; $defaults = array( 'show_option_all' => '', 'show_option_none' => '', 'orderby' => 'display_name', 'order' => 'ASC', 'include' => '', 'exclude' => '', 'multi' => 0, 'show' => 'display_name', 'echo' => 1, - 'selected' => 0, 'name' => 'user', 'class' => '' + 'selected' => 0, 'name' => 'user', 'class' => '', 'blog' => $blog_id, ); $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; @@ -530,7 +531,8 @@ function wp_dropdown_users( $args = '' ) { $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); - $query = "SELECT * FROM $wpdb->users"; + $blog_prefix = $wpdb->get_blog_prefix( $blog ); + $query = "SELECT {$wpdb->users}.* FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities'"; $query_where = array(); @@ -547,7 +549,7 @@ function wp_dropdown_users( $args = '' ) { $query_where[] = "ID NOT IN ($exclude)"; if ( $query_where ) - $query .= " WHERE " . join(' AND', $query_where); + $query .= " AND " . join(' AND', $query_where); $query .= " ORDER BY $orderby $order";