Make WordPress Core

Changeset 27046


Ignore:
Timestamp:
01/27/2014 11:09:08 PM (11 years ago)
Author:
helen
Message:

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

fixes #25348.

Location:
trunk/src/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r27036 r27046  
    198198
    199199    // Check the type of request
    200     if ( isset( $_REQUEST['autocomplete_type'] ) )
     200    // Current allowed values are `add` and `search`
     201    if ( isset( $_REQUEST['autocomplete_type'] ) && 'search' === $_REQUEST['autocomplete_type'] ) {
    201202        $type = $_REQUEST['autocomplete_type'];
    202     else
     203    } else {
    203204        $type = 'add';
     205    }
     206
     207    // Check the desired field for value
     208    // Current allowed values are `user_email` and `user_login`
     209    if ( isset( $_REQUEST['autocomplete_field'] ) && 'user_email' === $_REQUEST['autocomplete_field'] ) {
     210        $field = $_REQUEST['autocomplete_field'];
     211    } else {
     212        $field = 'user_login';
     213    }
    204214
    205215    // Exclude current users of this blog
    206     if ( isset( $_REQUEST['site_id'] ) )
     216    if ( isset( $_REQUEST['site_id'] ) ) {
    207217        $id = absint( $_REQUEST['site_id'] );
    208     else
     218    } else {
    209219        $id = get_current_blog_id();
     220    }
    210221
    211222    $include_blog_users = ( $type == 'search' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
     
    224235            /* translators: 1: user_login, 2: user_email */
    225236            'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ),
    226             'value' => $user->user_login,
     237            'value' => $user->$field,
    227238        );
    228239    }
  • trunk/src/wp-admin/js/user-suggest.js

    r26238 r27046  
    99            position.at = 'right bottom';
    1010        }
    11         $( '.wp-suggest-user' ).autocomplete({
    12             source:    ajaxurl + '?action=autocomplete-user&autocomplete_type=add' + id,
    13             delay:     500,
    14             minLength: 2,
    15             position:  position,
    16             open: function() {
    17                 $( this ).addClass( 'open' );
    18             },
    19             close: function() {
    20                 $( this ).removeClass( 'open' );
    21             }
     11        $( '.wp-suggest-user' ).each( function(){
     12            var $this = $( this ),
     13                autocompleteType = ( typeof $this.data( 'autocompleteType' ) !== 'undefined' ) ? $this.data( 'autocompleteType' ) : 'add',
     14                autocompleteField = ( typeof $this.data( 'autocompleteField' ) !== 'undefined' ) ? $this.data( 'autocompleteField' ) : 'user_login';
     15
     16            $this.autocomplete({
     17                source:    ajaxurl + '?action=autocomplete-user&autocomplete_type=' + autocompleteType + '&autocomplete_field=' + autocompleteField + id,
     18                delay:     500,
     19                minLength: 2,
     20                position:  position,
     21                open: function() {
     22                    $( this ).addClass( 'open' );
     23                },
     24                close: function() {
     25                    $( this ).removeClass( 'open' );
     26                }
     27            });
    2228        });
    2329    });
  • trunk/src/wp-admin/network/site-new.php

    r26518 r27046  
    107107$parent_file = 'sites.php';
    108108
     109wp_enqueue_script( 'user-suggest' );
     110
    109111require( ABSPATH . 'wp-admin/admin-header.php' );
    110112
     
    139141        <tr class="form-field form-required">
    140142            <th scope="row"><?php _e( 'Admin Email' ) ?></th>
    141             <td><input name="blog[email]" type="text" class="regular-text" title="<?php esc_attr_e( 'Email' ) ?>"/></td>
     143            <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>
    142144        </tr>
    143145        <tr class="form-field">
Note: See TracChangeset for help on using the changeset viewer.