Index: wp-admin/admin-ajax.php
===================================================================
--- wp-admin/admin-ajax.php (revision 19809)
+++ wp-admin/admin-ajax.php (working copy)
@@ -34,7 +34,7 @@ send_nosniff_header();
do_action( 'admin_init' );
-$core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'compression-test', 'imgedit-preview', 'oembed_cache' );
+$core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'compression-test', 'imgedit-preview', 'oembed_cache', 'autocomplete_user' );
$core_actions_post = array(
'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
Index: wp-admin/css/wp-admin.dev.css
===================================================================
--- wp-admin/css/wp-admin.dev.css (revision 19809)
+++ wp-admin/css/wp-admin.dev.css (working copy)
@@ -892,6 +892,67 @@ p.search-box {
margin: 0;
}
+#wpcontent input[type="text"].ajax-loading {
+ background: transparent url('../images/loading.gif') no-repeat right center;
+ visibility: visible;
+}
+
+ul#add-to-blog-users {
+ margin: 0 0 0 14px;
+}
+
+form#adduser ul.ui-autocomplete {
+ padding: 0;
+ margin: 0;
+ list-style: none;
+ position: absolute;
+ z-index: 10000;
+ border-width: 1px;
+ border-style: solid;
+
+ background-color: #ffffff;
+ border-color: gray;
+}
+
+form#adduser .ui-widget-content {
+ background: #ececec;
+}
+
+form#adduser .ui-widget-content li {
+ padding: 2px 5px;
+ white-space: nowrap;
+ text-align: left;
+ color: #101010;
+}
+
+form#adduser .ui-widget-content li a {
+ display: block;
+ height: 100%;
+ padding: 2px 5px;
+ color: #333;
+}
+
+form#adduser .ui-widget-content li a.ui-state-hover {
+ background-color: #f0f0b8;
+}
+
+form#adduser a.remove {
+ margin: 6px 0pt 0pt -12px;
+ cursor: pointer;
+ width: 10px;
+ height: 10px;
+ display: block;
+ float: left;
+ text-indent: -9999px;
+ overflow: hidden;
+ position: absolute;
+ background: transparent url(../images/xit.gif) no-repeat;
+}
+
+form#adduser a.remove:hover {
+ background: transparent url(../images/xit.gif) no-repeat -10px 0;
+}
+
/*------------------------------------------------------------------------------
3.0 - Actions
Index: wp-admin/includes/ajax-actions.php
===================================================================
--- wp-admin/includes/ajax-actions.php (revision 19809)
+++ wp-admin/includes/ajax-actions.php (working copy)
@@ -146,6 +146,41 @@ function wp_ajax_oembed_cache() {
wp_die( $return );
}
+function wp_ajax_autocomplete_user() {
+ $return = array();
+
+ // Exclude current users of this blog
+ $this_blog_users = new WP_User_Query( array(
+ 'blog_id' => get_current_blog_id()
+ ) );
+
+ $tbu_ids = array();
+ if ( !empty( $this_blog_users->results ) ) {
+ foreach( $this_blog_users->results as $this_blog_user ) {
+ $tbu_ids[] = $this_blog_user->ID;
+ }
+ }
+
+ $users = new WP_User_Query( array(
+ 'blog_id' => false,
+ 'search' => '*' . $_REQUEST['term'] . '*',
+ 'exclude' => $tbu_ids
+ ) );
+
+ if ( empty( $users->results ) ) {
+ $return[] = array();
+ } else {
+ foreach ( $users->results as $user ) {
+ $user_data = array();
+ $user_data['label'] = $user->user_login . ' (' . $user->user_email . ')';
+ $user_data['id'] = $user->ID;
+ $return[] = $user_data;
+ }
+ }
+
+ die( json_encode( $return ) );
+}
+
/*
* Ajax helper.
*/
Index: wp-admin/js/user-new.dev.js
new file mode 100644
===================================================================
---wp-admin/js/user-new.dev.js (revision 0)n+++wp-admin/js/user-new.dev.js (revision 0)
@@ -0,0 +1,50 @@
+(function($){
+ var ainput = $('#adduser-email');
+ var ulist = $('#add-to-blog-users');
+
+ function add_user_to_list( dname, user_id ) {
+ /* Don't add if it already exists */
+ if ( $('#atb-user-' + user_id).length ) {
+ return;
+ }
+
+ $(ulist).append('
x ' + dname + '');
+ $(ulist).append('');
+
+ $('#add-to-blog-users span.remove a').bind('click', function(){
+ remove_user_from_list( $(this).parents('.atb-user').attr('id').split('-').pop() );
+ return false;
+ });
+
+ $(ainput).val('');
+ }
+
+ function remove_user_from_list( uid ) {
+ $('#atb-user-' + uid).remove();
+ $('#atb-input-' + uid).remove();
+ }
+
+ $(document).ready(function() {
+
+ /* Prevent WP from running its form validation */
+ $('form#adduser').removeClass('validate');
+ $(ainput).parents('.form-field').removeClass('form-required');
+
+ /* Prevent WP core admin script from running */
+ /*$('form#adduser input[name="action"]').remove();*/
+
+ var options = {
+ source: ajaxurl + '?action=autocomplete_user',
+ appendTo: 'form#adduser',
+ select: function(event,ui){ add_user_to_list(ui.item.value,ui.item.id); },
+ search: function(){$(ainput).addClass('ajax-loading');},
+ open: function(){$(ainput).removeClass('ajax-loading');},
+ close: function(){$(ainput).val('');},
+ delay: 500, // miliseconds
+ };
+
+ a = $(ainput).autocomplete(options);
+ });
+
+})(jQuery);
+
Index: wp-admin/user-new.php
===================================================================
--- wp-admin/user-new.php (revision 19809)
+++ wp-admin/user-new.php (working copy)
@@ -38,50 +38,62 @@ Please click the following link to activate your user account:
if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
check_admin_referer( 'add-user', '_wpnonce_add-user' );
- $user_details = null;
- if ( false !== strpos($_REQUEST[ 'email' ], '@') ) {
- $user_details = get_user_by('email', $_REQUEST[ 'email' ]);
+ $add_users = isset( $_REQUEST['add_ids'] ) ? (array)$_REQUEST['add_ids'] : $_REQUEST['email'];
+
+ $add_users_data = array();
+ if ( is_array( $add_users ) ) {
+ foreach( $add_users as $add_id ) {
+ if ( current_user_can( 'promote_user', $add_id ) ) {
+ $add_users_data[] = get_userdata( (int)$add_id );
+ }
+ }
} else {
- if ( is_super_admin() ) {
- $user_details = get_user_by('login', $_REQUEST[ 'email' ]);
+ if ( false !== strpos($add_users, '@') ) {
+ $add_users_data[] = get_user_by('email', $add_users);
} else {
- wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
- die();
+ if ( is_super_admin() ) {
+ $add_users_data[] = get_user_by('login', $add_users);
+ } else {
+ wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
+ die();
+ }
}
+
+ if ( ! current_user_can('promote_user', $add_users_data[0]->ID) )
+ wp_die(__('Cheatin’ uh?'));
}
- if ( !$user_details ) {
+ if ( empty( $add_users_data ) ) {
wp_redirect( add_query_arg( array('update' => 'does_not_exist'), 'user-new.php' ) );
die();
}
-
- if ( ! current_user_can('promote_user', $user_details->ID) )
- wp_die(__('Cheatin’ uh?'));
-
- // Adding an existing user to this blog
- $new_user_email = $user_details->user_email;
- $redirect = 'user-new.php';
- $username = $user_details->user_login;
- $user_id = $user_details->ID;
- if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
- $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
- } else {
- if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
- add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
- $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
+
+ foreach( $add_users_data as $user_details ) {
+ // Adding an existing user to this blog
+ $new_user_email = $user_details->user_email;
+ $redirect = 'user-new.php';
+ $username = $user_details->user_login;
+ $user_id = $user_details->ID;
+ if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
+ $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
} else {
- $newuser_key = substr( md5( $user_id ), 0, 5 );
- add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
- /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */
- $message = __( 'Hi,
-
+ if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
+ add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
+ $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
+ } else {
+ $newuser_key = substr( md5( $user_id ), 0, 5 );
+ add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
+ /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */
+ $message = __( 'Hi,
+
You\'ve been invited to join \'%1$s\' at
%2$s with the role of %3$s.
Please click the following link to confirm the invite:
%4$s' );
- wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ), sprintf($message, get_option('blogname'), home_url(), $_REQUEST[ 'role' ], home_url("/newbloguser/$newuser_key/")));
- $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
+ wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ), sprintf($message, get_option('blogname'), site_url(), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/")));
+ $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
+ }
}
}
wp_redirect( $redirect );
@@ -178,6 +190,8 @@ get_current_screen()->set_help_sidebar(
wp_enqueue_script('wp-ajax-response');
wp_enqueue_script('user-profile');
+wp_enqueue_script('user-new');
+wp_enqueue_script('jquery-ui-autocomplete');
require_once ('admin-header.php');
@@ -265,7 +279,7 @@ if ( is_multisite() ) {