Autocomplete for the new site admin email. Better than trying to remember which email address you used.

fixes #25348.


git-svn-id: https://develop.svn.wordpress.org/trunk@27046 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Helen Hou-Sandi 2014-01-27 23:09:08 +00:00
parent bd9729c22d
commit 91b0e15ef8
3 changed files with 37 additions and 18 deletions

View File

@ -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,
);
}

View File

@ -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 );
})( jQuery );

View File

@ -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 ) ) {
</tr>
<tr class="form-field form-required">
<th scope="row"><?php _e( 'Admin Email' ) ?></th>
<td><input name="blog[email]" type="text" class="regular-text" title="<?php esc_attr_e( 'Email' ) ?>"/></td>
<td><input name="blog[email]" type="text" class="regular-text wp-suggest-user" data-autocomplete-type="search" data-autocomplete-field="user_email" title="<?php esc_attr_e( 'Email' ) ?>"/></td>
</tr>
<tr class="form-field">
<td colspan="2"><?php _e( 'A new user will be created if the above email address is not in the database.' ) ?><br /><?php _e( 'The username and password will be mailed to this email address.' ) ?></td>