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

git-svn-id: http://svn.automattic.com/wordpress/trunk@19897 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2012-02-10 08:45:17 +00:00
parent 570a54053f
commit 481959acec
8 changed files with 96 additions and 2 deletions

View File

@ -34,7 +34,7 @@ send_nosniff_header();
do_action( 'admin_init' );
$core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed_cache' );
$core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed_cache', 'autocomplete-user' );
$core_actions_post = array(
'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',

View File

@ -892,6 +892,45 @@ p.search-box {
margin: 0;
}
input[type="text"].ui-autocomplete-loading {
background: transparent url('../images/loading.gif') no-repeat right center;
visibility: visible;
}
ul#add-to-blog-users {
margin: 0 0 0 14px;
}
.ui-autocomplete {
padding: 0;
margin: 0;
list-style: none;
position: absolute;
z-index: 10000;
border-width: 1px;
border-style: solid;
background-color: #ececec;
border-color: gray;
}
.ui-autocomplete li {
padding: 2px 5px;
white-space: nowrap;
text-align: left;
color: #101010;
}
.ui-autocomplete li a {
display: block;
height: 100%;
padding: 2px 5px;
color: #333;
}
.ui-autocomplete li a.ui-state-hover {
background-color: #f0f0b8;
}
/*------------------------------------------------------------------------------
3.0 - Actions

View File

@ -149,6 +149,38 @@ function wp_ajax_oembed_cache() {
wp_die( $return );
}
function wp_ajax_autocomplete_user() {
if ( !is_multisite() || !current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) || !is_super_admin() && apply_filters( 'autocomplete_users_for_site_admins', false ) )
wp_die( -1 );
$return = array();
// Exclude current users of this blog
if ( isset( $_REQUEST['site_id'] ) )
$id = absint( $_REQUEST['site_id'] );
else
$id = get_current_blog_id();
$this_blog_users = get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) );
$users = get_users( array(
'blog_id' => false,
'search' => '*' . $_REQUEST['term'] . '*',
'exclude' => $this_blog_users,
'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
) );
foreach ( $users as $user ) {
$return[] = array(
/* translators: 1: user_login, 2: user_email */
'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ),
'value' => $user->user_login,
);
}
wp_die( json_encode( $return ) );
}
/*
* Ajax helper.
*/

View File

@ -0,0 +1,9 @@
jQuery( function($) {
var id = typeof( current_site_id ) != 'undefined' ? '&site_id=' + current_site_id : '';
$( '#adduser-email, #newuser' ).autocomplete({
source: ajaxurl + '?action=autocomplete-user' + id,
delay: 500,
minLength: 2,
});
});

View File

View File

@ -171,8 +171,18 @@ $title = sprintf( __('Edit Site: %s'), $site_url_no_http );
$parent_file = 'sites.php';
$submenu_file = 'sites.php';
if ( current_user_can( 'promote_users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) && !wp_is_large_network( 'users' ) )
wp_enqueue_script( 'user-search' );
require('../admin-header.php'); ?>
<script type='text/javascript'>
/* <![CDATA[ */
var current_site_id = <?php echo $id; ?>;
/* ]]> */
</script>
<div class="wrap">
<?php screen_icon('ms-admin'); ?>
<h2 id="edit-site"><?php echo $title_site_url_linked ?></h2>

View File

@ -178,8 +178,10 @@ get_current_screen()->set_help_sidebar(
wp_enqueue_script('wp-ajax-response');
wp_enqueue_script('user-profile');
if ( is_multisite() && current_user_can( 'promote_users' ) && !wp_is_large_network( 'users' ) && is_super_admin() || apply_filters( 'autocomplete_users_for_site_admins', false ) )
wp_enqueue_script( 'user-search' );
require_once ('admin-header.php');
require_once( 'admin-header.php' );
if ( isset($_GET['update']) ) {
$messages = array();

View File

@ -260,6 +260,8 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter' ), false, 1 );
$scripts->add( 'user-search', "/wp-admin/js/user-search$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
$scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 );
$scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wpdialogs' ), false, 1 );