WordPress.org

Make WordPress Core

Changeset 19897


Ignore:
Timestamp:
02/10/2012 08:45:17 AM (9 years ago)
Author:
markjaquith
Message:

Autocomplete for add-user screens in multisite. props boonebgorges, Japh, DrewAPicture, PeteMall, nacin, koopersmith, markjaquith. see #19810.

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r19874 r19897  
    3535do_action( 'admin_init' );
    3636
    37 $core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed_cache' );
     37$core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed_cache', 'autocomplete-user' );
    3838
    3939$core_actions_post = array(
  • trunk/wp-admin/css/wp-admin.dev.css

    r19826 r19897  
    893893}
    894894
     895input[type="text"].ui-autocomplete-loading {
     896    background: transparent url('../images/loading.gif') no-repeat right center;
     897    visibility: visible;
     898}
     899
     900ul#add-to-blog-users {
     901    margin: 0 0 0 14px;
     902}
     903
     904.ui-autocomplete {
     905    padding: 0;
     906    margin: 0;
     907    list-style: none;
     908    position: absolute;
     909    z-index: 10000;
     910    border-width: 1px;
     911    border-style: solid;
     912
     913    background-color: #ececec;
     914    border-color: gray;
     915}
     916
     917.ui-autocomplete li {
     918    padding: 2px 5px;
     919    white-space: nowrap;
     920    text-align: left;
     921    color: #101010;
     922}
     923
     924.ui-autocomplete li a {
     925    display: block;
     926    height: 100%;
     927    padding: 2px 5px;
     928    color: #333;
     929}
     930
     931.ui-autocomplete li a.ui-state-hover {
     932    background-color: #f0f0b8;
     933}
    895934
    896935/*------------------------------------------------------------------------------
  • trunk/wp-admin/includes/ajax-actions.php

    r19853 r19897  
    148148    $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0';
    149149    wp_die( $return );
     150}
     151
     152function wp_ajax_autocomplete_user() {
     153    if ( !is_multisite() || !current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) || !is_super_admin() && apply_filters( 'autocomplete_users_for_site_admins', false ) )
     154        wp_die( -1 );
     155   
     156    $return = array();
     157
     158    // Exclude current users of this blog
     159    if ( isset( $_REQUEST['site_id'] ) )
     160        $id = absint( $_REQUEST['site_id'] );
     161    else
     162        $id = get_current_blog_id();
     163
     164    $this_blog_users = get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) );
     165
     166    $users = get_users( array(
     167        'blog_id' => false,
     168        'search'  => '*' . $_REQUEST['term'] . '*',
     169        'exclude' => $this_blog_users,
     170        'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
     171    ) );   
     172
     173    foreach ( $users as $user ) {
     174        $return[] = array(
     175            /* translators: 1: user_login, 2: user_email */
     176            'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ),
     177            'value' => $user->user_login,
     178        );
     179    }
     180
     181    wp_die( json_encode( $return ) );
    150182}
    151183
  • trunk/wp-admin/network/site-users.php

    r19593 r19897  
    172172$submenu_file = 'sites.php';
    173173
     174if ( current_user_can( 'promote_users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) && !wp_is_large_network( 'users' ) )
     175    wp_enqueue_script( 'user-search' );
     176
    174177require('../admin-header.php'); ?>
     178
     179<script type='text/javascript'>
     180/* <![CDATA[ */
     181var current_site_id = <?php echo $id; ?>;
     182/* ]]> */
     183</script>
     184
    175185
    176186<div class="wrap">
  • trunk/wp-admin/user-new.php

    r19712 r19897  
    179179wp_enqueue_script('wp-ajax-response');
    180180wp_enqueue_script('user-profile');
    181 
    182 require_once ('admin-header.php');
     181if ( is_multisite() && current_user_can( 'promote_users' ) && !wp_is_large_network( 'users' ) && is_super_admin() || apply_filters( 'autocomplete_users_for_site_admins', false ) )
     182    wp_enqueue_script( 'user-search' );
     183
     184require_once( 'admin-header.php' );
    183185
    184186if ( isset($_GET['update']) ) {
  • trunk/wp-includes/script-loader.php

    r19853 r19897  
    261261    $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter' ), false, 1 );
    262262
     263    $scripts->add( 'user-search', "/wp-admin/js/user-search$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
     264
    263265    $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 );
    264266
Note: See TracChangeset for help on using the changeset viewer.