diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 08d9de44b6..caf6311168 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -197,16 +197,27 @@ function wp_ajax_autocomplete_user() { $return = array(); // Check the type of request - if ( isset( $_REQUEST['autocomplete_type'] ) ) + // Current allowed values are `add` and `search` + if ( isset( $_REQUEST['autocomplete_type'] ) && 'search' === $_REQUEST['autocomplete_type'] ) { $type = $_REQUEST['autocomplete_type']; - else + } else { $type = 'add'; + } + + // Check the desired field for value + // Current allowed values are `user_email` and `user_login` + if ( isset( $_REQUEST['autocomplete_field'] ) && 'user_email' === $_REQUEST['autocomplete_field'] ) { + $field = $_REQUEST['autocomplete_field']; + } else { + $field = 'user_login'; + } // Exclude current users of this blog - if ( isset( $_REQUEST['site_id'] ) ) + if ( isset( $_REQUEST['site_id'] ) ) { $id = absint( $_REQUEST['site_id'] ); - else + } else { $id = get_current_blog_id(); + } $include_blog_users = ( $type == 'search' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() ); $exclude_blog_users = ( $type == 'add' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() ); @@ -223,7 +234,7 @@ function wp_ajax_autocomplete_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, + 'value' => $user->$field, ); } diff --git a/src/wp-admin/js/user-suggest.js b/src/wp-admin/js/user-suggest.js index 130c3d1adf..0113ded0e9 100644 --- a/src/wp-admin/js/user-suggest.js +++ b/src/wp-admin/js/user-suggest.js @@ -8,17 +8,23 @@ position.my = 'right top'; position.at = 'right bottom'; } - $( '.wp-suggest-user' ).autocomplete({ - source: ajaxurl + '?action=autocomplete-user&autocomplete_type=add' + id, - delay: 500, - minLength: 2, - position: position, - open: function() { - $( this ).addClass( 'open' ); - }, - close: function() { - $( this ).removeClass( 'open' ); - } + $( '.wp-suggest-user' ).each( function(){ + var $this = $( this ), + autocompleteType = ( typeof $this.data( 'autocompleteType' ) !== 'undefined' ) ? $this.data( 'autocompleteType' ) : 'add', + autocompleteField = ( typeof $this.data( 'autocompleteField' ) !== 'undefined' ) ? $this.data( 'autocompleteField' ) : 'user_login'; + + $this.autocomplete({ + source: ajaxurl + '?action=autocomplete-user&autocomplete_type=' + autocompleteType + '&autocomplete_field=' + autocompleteField + id, + delay: 500, + minLength: 2, + position: position, + open: function() { + $( this ).addClass( 'open' ); + }, + close: function() { + $( this ).removeClass( 'open' ); + } + }); }); }); -})( jQuery ); \ No newline at end of file +})( jQuery ); diff --git a/src/wp-admin/network/site-new.php b/src/wp-admin/network/site-new.php index 672d7e869e..8765ab98c3 100644 --- a/src/wp-admin/network/site-new.php +++ b/src/wp-admin/network/site-new.php @@ -106,6 +106,8 @@ if ( isset($_GET['update']) ) { $title = __('Add New Site'); $parent_file = 'sites.php'; +wp_enqueue_script( 'user-suggest' ); + require( ABSPATH . 'wp-admin/admin-header.php' ); ?> @@ -138,7 +140,7 @@ if ( ! empty( $messages ) ) {