Make WordPress Core

Ticket #19810: 19810.13.patch

File 19810.13.patch, 3.3 KB (added by Japh, 13 years ago)

A modification to allow the autocomplete to be used for more purposes, such as search fields. This should also make it easier to add availability checking too.

  • wp-admin/users.php

     
    338338                wp_redirect( add_query_arg( 'paged', $total_pages ) );
    339339                exit;
    340340        }
     341
     342        if ( current_user_can( 'promote_users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) && !wp_is_large_network( 'users' ) )
     343                wp_enqueue_script( 'user-search' );
     344
    341345        include('./admin-header.php');
    342346
    343347        $messages = array();
  • wp-admin/includes/ajax-actions.php

     
    155155       
    156156        $return = array();
    157157
     158        // Check the type of request
     159        if ( isset( $_REQUEST['autocomplete_type'] ) )
     160                $type = $_REQUEST['autocomplete_type'];
     161        else
     162                $type = 'add';
     163
    158164        // Exclude current users of this blog
    159165        if ( isset( $_REQUEST['site_id'] ) )
    160166                $id = absint( $_REQUEST['site_id'] );
    161167        else
    162168                $id = get_current_blog_id();
    163169
    164         $this_blog_users = get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) );
     170        $include_blog_users = ( $type == 'search' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
     171        $exclude_blog_users = ( $type == 'add' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
    165172
    166173        $users = get_users( array(
    167174                'blog_id' => false,
    168175                'search'  => '*' . $_REQUEST['term'] . '*',
    169                 'exclude' => $this_blog_users,
     176                'include' => $include_blog_users,
     177                'exclude' => $exclude_blog_users,
    170178                'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
    171         ) );   
     179        ) );
    172180
    173181        foreach ( $users as $user ) {
    174182                $return[] = array(
     
    16751683
    16761684        update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
    16771685        wp_die( 1 );
    1678 }
    1679  No newline at end of file
     1686}
  • wp-admin/js/user-search.dev.js

     
    22        var id = typeof( current_site_id ) != 'undefined' ? '&site_id=' + current_site_id : '';
    33
    44        $( '#adduser-email, #newuser' ).autocomplete({
    5                 source:   ajaxurl + '?action=autocomplete-user' + id,
     5                source:   ajaxurl + '?action=autocomplete-user&autocomplete_type=add' + id,
    66                delay:    500,
    77                minLength: 2
    88        });
    9 });
    10  No newline at end of file
     9
     10        $( '#user-search-input' ).autocomplete({
     11                source:   ajaxurl + '?action=autocomplete-user&autocomplete_type=search' + id,
     12                delay:    500,
     13                minLength: 2
     14        });
     15});
  • wp-admin/network/users.php

     
    247247        '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
    248248);
    249249
     250if ( current_user_can( 'promote_users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) && !wp_is_large_network( 'users' ) )
     251        wp_enqueue_script( 'user-search' );
     252
    250253require_once( '../admin-header.php' );
    251254
    252255if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {