Ticket #19867: 19867.diff
File 19867.diff, 4.3 KB (added by , 11 years ago) |
---|
-
src/wp-includes/user.php
1163 1163 'include' => '', 'exclude' => '', 'multi' => 0, 1164 1164 'show' => 'display_name', 'echo' => 1, 1165 1165 'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '', 1166 'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false 1166 'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false, 1167 'autocomplete' => false 1167 1168 ); 1168 1169 1169 1170 $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; … … 1175 1176 $query_args['fields'] = array( 'ID', 'user_login', $show ); 1176 1177 $users = get_users( $query_args ); 1177 1178 1179 /** 1180 * !!!!!!! 1181 * 1182 * wp_dropdown_users() defaults to using jQuery UI autocomplete in the admin 1183 * when there are over 100 users. To use autocomplete on the front-end, 1184 * set the arg to true when calling the function. 1185 * 1186 * @since 3.9.0 1187 * @param bool $autocomplete Whether or not to use autocomplete for the dropdown. 1188 * @param array $users The results of the get_users() call. Most useful for count(). 1189 * @param array $args The passed args to wp_dropdown_users(). 1190 */ 1191 if ( is_admin() ) { 1192 $autocomplete = apply_filters( 'admin_user_dropdown_autocomplete', count( $users ) > 100, $users, $args ); 1193 } 1194 1178 1195 $output = ''; 1179 1196 if ( !empty($users) && ( empty($hide_if_only_one_author) || count($users) > 1 ) ) { 1180 1197 $name = esc_attr( $name ); … … 1183 1200 else 1184 1201 $id = $id ? " id='" . esc_attr( $id ) . "'" : " id='$name'"; 1185 1202 1186 $output = "<select name='{$name}'{$id} class='$class'>\n"; 1203 if ( $autocomplete ) { 1204 wp_enqueue_script( 'user-suggest' ); 1187 1205 1188 if ( $show_option_all ) 1189 $output .= "\t<option value='0'>$show_option_all</option>\n"; 1206 $display = ''; 1190 1207 1191 if ( $show_option_none) {1192 $_selected = selected( -1, $selected, false);1193 $output .= "\t<option value='-1'$_selected>$show_option_none</option>\n";1194 }1208 if ( $selected > 0 ) { 1209 $user = get_user_by( 'id', $selected ); 1210 $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')'; 1211 } 1195 1212 1196 $found_selected = false; 1197 foreach ( (array) $users as $user ) { 1198 $user->ID = (int) $user->ID; 1199 $_selected = selected( $user->ID, $selected, false ); 1200 if ( $_selected ) 1201 $found_selected = true; 1202 $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')'; 1203 $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; 1204 } 1213 $output = "<input type='text' name='{$name}'{$id} class='$class wp-suggest-user' data-autocomplete-type='search' data-autocomplete-field='user_id' value='{$selected}' />\n"; 1205 1214 1206 if ( $include_selected && ! $found_selected && ( $selected > 0 ) ) { 1207 $user = get_userdata( $selected ); 1208 $_selected = selected( $user->ID, $selected, false ); 1209 $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')'; 1210 $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; 1215 $output .= "<input type='text' class='wp-suggest-user-overlay hide-if-no-js' value='{$display}' />"; 1216 } else { 1217 $output = "<select name='{$name}'{$id} class='$class'>\n"; 1218 1219 if ( $show_option_all ) 1220 $output .= "\t<option value='0'>$show_option_all</option>\n"; 1221 1222 if ( $show_option_none ) { 1223 $_selected = selected( -1, $selected, false ); 1224 $output .= "\t<option value='-1'$_selected>$show_option_none</option>\n"; 1225 } 1226 1227 $found_selected = false; 1228 foreach ( (array) $users as $user ) { 1229 $user->ID = (int) $user->ID; 1230 $_selected = selected( $user->ID, $selected, false ); 1231 if ( $_selected ) 1232 $found_selected = true; 1233 $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')'; 1234 $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; 1235 } 1236 1237 if ( $include_selected && ! $found_selected && ( $selected > 0 ) ) { 1238 $user = get_userdata( $selected ); 1239 $_selected = selected( $user->ID, $selected, false ); 1240 $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')'; 1241 $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; 1242 } 1243 1244 $output .= "</select>"; 1211 1245 } 1212 1213 $output .= "</select>";1214 1246 } 1215 1247 1216 1248 /**