Make WordPress Core


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.