WordPress.org

Make WordPress Core

Ticket #11086: 11086-wp_dropdown_users.diff

File 11086-wp_dropdown_users.diff, 1.7 KB (added by nacin, 8 years ago)
  • wp-includes/user.php

     
    495495 * <li>selected - Which User ID is selected.</li>
    496496 * <li>name - Default is 'user'. Name attribute of select element.</li>
    497497 * <li>class - Class attribute of select element.</li>
     498 * <li>blog_id - The Blog id of the blog for setups that use more than one blog.</li>
    498499 * </ol>
    499500 *
    500501 * @since 2.3.0
     
    504505 * @return string|null Null on display. String of HTML content on retrieve.
    505506 */
    506507function wp_dropdown_users( $args = '' ) {
    507         global $wpdb;
     508        global $wpdb, $blog_id;
    508509        $defaults = array(
    509510                'show_option_all' => '', 'show_option_none' => '',
    510511                'orderby' => 'display_name', 'order' => 'ASC',
    511512                'include' => '', 'exclude' => '', 'multi' => 0,
    512513                'show' => 'display_name', 'echo' => 1,
    513                 'selected' => 0, 'name' => 'user', 'class' => ''
     514                'selected' => 0, 'name' => 'user', 'class' => '', 'blog_id' = $blog_id,
    514515        );
    515516
    516517        $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
     
    518519        $r = wp_parse_args( $args, $defaults );
    519520        extract( $r, EXTR_SKIP );
    520521
    521         $query = "SELECT * FROM $wpdb->users";
    522 
     522        $query = "SELECT {$wpdb->users}.* FROM $wpdb->users, $wpdb->usermeta";
    523523        $query_where = array();
    524524
    525525        if ( is_array($include) )
     
    534534        if ( $exclude )
    535535                $query_where[] = "ID NOT IN ($exclude)";
    536536
     537        $query .= " WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$wpdb->prefix}capabilities'"
    537538        if ( $query_where )
    538                 $query .= " WHERE " . join(' AND', $query_where);
     539                $query .= " AND " . join(' AND', $query_where);
    539540
    540541        $query .= " ORDER BY $orderby $order";
    541542