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

fixes #25348.

Built from https://develop.svn.wordpress.org/trunk@27046


git-svn-id: http://core.svn.wordpress.org/trunk@26920 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2014-01-27 23:10:12 +00:00
parent d39d60e841
commit 291ed370b4
4 changed files with 38 additions and 19 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

@ -1 +1 @@
!function(a){var b="undefined"!=typeof current_site_id?"&site_id="+current_site_id:"";a(document).ready(function(){var c={offset:"0, -1"};"undefined"!=typeof isRtl&&isRtl&&(c.my="right top",c.at="right bottom"),a(".wp-suggest-user").autocomplete({source:ajaxurl+"?action=autocomplete-user&autocomplete_type=add"+b,delay:500,minLength:2,position:c,open:function(){a(this).addClass("open")},close:function(){a(this).removeClass("open")}})})}(jQuery);
!function(a){var b="undefined"!=typeof current_site_id?"&site_id="+current_site_id:"";a(document).ready(function(){var c={offset:"0, -1"};"undefined"!=typeof isRtl&&isRtl&&(c.my="right top",c.at="right bottom"),a(".wp-suggest-user").each(function(){var d=a(this),e="undefined"!=typeof d.data("autocompleteType")?d.data("autocompleteType"):"add",f="undefined"!=typeof d.data("autocompleteField")?d.data("autocompleteField"):"user_login";d.autocomplete({source:ajaxurl+"?action=autocomplete-user&autocomplete_type="+e+"&autocomplete_field="+f+b,delay:500,minLength:2,position:c,open:function(){a(this).addClass("open")},close:function(){a(this).removeClass("open")}})})})}(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>