Make WordPress Core

Changeset 20279


Ignore:
Timestamp:
03/24/2012 04:54:58 AM (13 years ago)
Author:
markjaquith
Message:

Autocomplete site names in Network Admin. More user completion areas. props Japh, DrewAPicture. see #19810.

Location:
trunk
Files:
2 added
12 edited

Legend:

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

    r20190 r20279  
    3737$core_actions_get = array(
    3838    'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
    39     'autocomplete-user', 'dashboard-widgets',
     39    'autocomplete-user', 'autocomplete-site', 'dashboard-widgets',
    4040);
    4141
  • trunk/wp-admin/css/wp-admin.dev.css

    r20272 r20279  
    901901.ui-autocomplete li a.ui-state-hover {
    902902    background-color: #f0f0b8;
     903    cursor: pointer;
    903904}
    904905
  • trunk/wp-admin/includes/ajax-actions.php

    r20190 r20279  
    161161    $return = array();
    162162
     163    // Check the type of request
     164    if ( isset( $_REQUEST['autocomplete_type'] ) )
     165        $type = $_REQUEST['autocomplete_type'];
     166    else
     167        $type = 'add';
     168
    163169    // Exclude current users of this blog
    164170    if ( isset( $_REQUEST['site_id'] ) )
     
    167173        $id = get_current_blog_id();
    168174
    169     $this_blog_users = get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) );
     175    $include_blog_users = ( $type == 'search' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
     176    $exclude_blog_users = ( $type == 'add' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
    170177
    171178    $users = get_users( array(
    172179        'blog_id' => false,
    173180        'search'  => '*' . $_REQUEST['term'] . '*',
    174         'exclude' => $this_blog_users,
     181        'include' => $include_blog_users,
     182        'exclude' => $exclude_blog_users,
    175183        'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
    176184    ) );
     
    205213    }
    206214    wp_die();
     215}
     216
     217function wp_ajax_autocomplete_site() {
     218    if ( ! is_multisite()
     219        || ! current_user_can( 'manage_sites' )
     220        || wp_is_large_network( 'sites' )
     221        || ! is_super_admin()
     222    ) {
     223        wp_die( -1 );
     224    }
     225
     226    $return = array();
     227
     228    global $wpdb;
     229    $like_escaped_term = '%' . like_escape( stripslashes( $_REQUEST['term'] ) ) . '%';
     230    $sites = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE ( domain LIKE %s OR path LIKE %s ) AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $like_escaped_term, $like_escaped_term ), ARRAY_A );
     231
     232    if ( empty( $sites ) )
     233        wp_die( -1 );
     234
     235    foreach ( (array) $sites as $details ) {
     236        $blogname = get_blog_option( $details['blog_id'], 'blogname' );
     237        $return[] = array(
     238            'label' => sprintf( '%1$s (%2$s)', $blogname, $details['domain'] . $details['path'] ),
     239            'value' => $details['domain']
     240        );
     241    }
     242
     243    wp_die( json_encode( $return ) );
    207244}
    208245
  • trunk/wp-admin/includes/dashboard.php

    r20272 r20279  
    417417        $actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
    418418
     419    if ( is_multisite()
     420        && current_user_can( 'promote_users' )
     421        && ! wp_is_large_network( 'users' )
     422        && is_super_admin()
     423        && is_network_admin()
     424    ) {
     425        wp_enqueue_script( 'user-search' );
     426    }
     427    if ( is_multisite()
     428        && current_user_can( 'manage_sites' )
     429        && ! wp_is_large_network( 'sites' )
     430        && is_super_admin()
     431        && is_network_admin()
     432    ) {
     433        wp_enqueue_script( 'site-search' );
     434    }
     435
    419436    $c_users = get_user_count();
    420437    $c_blogs = get_blog_count();
     
    441458    <form name="searchform" action="<?php echo network_admin_url('users.php'); ?>" method="get">
    442459        <p>
    443             <input type="search" name="s" value="" size="17" />
     460            <input type="search" name="s" value="" size="17" id="all-user-search-input" />
    444461            <?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
    445462        </p>
     
    448465    <form name="searchform" action="<?php echo network_admin_url('sites.php'); ?>" method="get">
    449466        <p>
    450             <input type="search" name="s" value="" size="17" />
     467            <input type="search" name="s" value="" size="17" id="site-search-input" />
    451468            <?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
    452469        </p>
  • trunk/wp-admin/index.php

    r19920 r20279  
    8989    '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
    9090);
    91 
     91   
    9292include (ABSPATH . 'wp-admin/admin-header.php');
    9393
  • trunk/wp-admin/js/user-search.dev.js

    r19903 r20279  
    33
    44    $( '#adduser-email, #newuser' ).autocomplete({
    5         source:   ajaxurl + '?action=autocomplete-user' + id,
     5        source:   ajaxurl + '?action=autocomplete-user&autocomplete_type=add' + id,
     6        delay:    500,
     7        minLength: 2
     8    });
     9
     10    $( '#user-search-input' ).autocomplete({
     11        source:   ajaxurl + '?action=autocomplete-user&autocomplete_type=search' + id,
     12        delay:    500,
     13        minLength: 2
     14    });
     15
     16    $( '#all-user-search-input' ).autocomplete({
     17        source:   ajaxurl + '?action=autocomplete-user&autocomplete_type=search-all' + id,
    618        delay:    500,
    719        minLength: 2
  • trunk/wp-admin/js/user-search.js

    r19904 r20279  
    1 jQuery(function(a){var b=typeof(current_site_id)!="undefined"?"&site_id="+current_site_id:"";a("#adduser-email, #newuser").autocomplete({source:ajaxurl+"?action=autocomplete-user"+b,delay:500,minLength:2})});
     1jQuery(function($){var id=typeof(current_site_id)!="undefined"?"&site_id="+current_site_id:"";$("#adduser-email, #newuser").autocomplete({source:ajaxurl+"?action=autocomplete-user&autocomplete_type=add"+id,delay:500,minLength:2});$("#user-search-input").autocomplete({source:ajaxurl+"?action=autocomplete-user&autocomplete_type=search"+id,delay:500,minLength:2});$("#all-user-search-input").autocomplete({source:ajaxurl+"?action=autocomplete-user&autocomplete_type=search-all"+id,delay:500,minLength:2})});
  • trunk/wp-admin/network/site-users.php

    r20196 r20279  
    172172$submenu_file = 'sites.php';
    173173
    174 if ( current_user_can( 'promote_users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) && !wp_is_large_network( 'users' ) )
     174if ( ! wp_is_large_network( 'users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) )
    175175    wp_enqueue_script( 'user-search' );
    176176
  • trunk/wp-admin/network/sites.php

    r20092 r20279  
    283283$wp_list_table->prepare_items();
    284284
     285if ( ! wp_is_large_network( 'sites' ) )
     286    wp_enqueue_script( 'site-search' );
     287
    285288require_once( '../admin-header.php' );
    286289?>
  • trunk/wp-admin/network/users.php

    r20093 r20279  
    246246);
    247247
     248if ( is_multisite()
     249    && current_user_can( 'promote_users' )
     250    && ! wp_is_large_network( 'users' )
     251    && is_super_admin()
     252) {
     253    wp_enqueue_script( 'user-search' );
     254}
     255
    248256require_once( '../admin-header.php' );
    249257
     
    289297
    290298    <form action="" method="get" class="search-form">
    291         <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
     299        <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?>
    292300    </form>
    293301
  • trunk/wp-admin/users.php

    r19640 r20279  
    339339        exit;
    340340    }
     341
     342    if ( is_multisite()
     343        && current_user_can( 'promote_users' )
     344        && ! wp_is_large_network( 'users' )
     345        && ( is_super_admin() || apply_filters( 'autocomplete_users_for_site_admins', false ) )
     346    ) {
     347        wp_enqueue_script( 'user-search' );
     348    }
     349
    341350    include('./admin-header.php');
    342351
  • trunk/wp-includes/script-loader.php

    r20179 r20279  
    269269    $scripts->add( 'user-search', "/wp-admin/js/user-search$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
    270270
     271    $scripts->add( 'site-search', "/wp-admin/js/site-search$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
     272
    271273    $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 );
    272274
Note: See TracChangeset for help on using the changeset viewer.