Remove user/site suggestions (autocompletion) from search inputs, as the UX isn't proper.

* Removes all instances of site-search, so away it goes. Sidesteps a number of bugs with site-search.
 * Renames user-search to user-suggest, which means it better describes the current behavior (autocompletion) while allowing for future behavior (instant search).
 * Ties user suggestions to a single .wp-suggest-user class.

with help from markjaquith, helenyhou, wonderboymusic. 
fixes #20835.



git-svn-id: http://core.svn.wordpress.org/trunk@21003 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2012-06-05 18:51:33 +00:00
parent 5cba80ee25
commit 3ebea2f218
14 changed files with 23 additions and 104 deletions

View File

@ -38,7 +38,7 @@ do_action( 'admin_init' );
$core_actions_get = array(
'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
'autocomplete-user', 'autocomplete-site', 'dashboard-widgets',
'autocomplete-user', 'dashboard-widgets',
);
$core_actions_post = array(

View File

@ -212,30 +212,6 @@ function wp_ajax_dashboard_widgets() {
wp_die();
}
function wp_ajax_autocomplete_site() {
if ( ! is_multisite() || ! current_user_can( 'manage_sites' ) || wp_is_large_network( 'sites' ) )
wp_die( -1 );
$return = array();
global $wpdb;
$like_escaped_term = '%' . like_escape( stripslashes( $_REQUEST['term'] ) ) . '%';
$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 );
if ( empty( $sites ) )
wp_die( -1 );
foreach ( (array) $sites as $details ) {
$blogname = get_blog_option( $details['blog_id'], 'blogname' );
$return[] = array(
'label' => sprintf( '%1$s (%2$s)', $blogname, $details['domain'] . $details['path'] ),
'value' => $details['domain']
);
}
wp_die( json_encode( $return ) );
}
/*
* Ajax helper.
*/

View File

@ -414,12 +414,6 @@ function wp_network_dashboard_right_now() {
if ( current_user_can('create_users') )
$actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
if ( ! wp_is_large_network( 'users' ) )
wp_enqueue_script( 'user-search' );
if ( ! wp_is_large_network( 'sites' ) )
wp_enqueue_script( 'site-search' );
$c_users = get_user_count();
$c_blogs = get_blog_count();
@ -442,16 +436,16 @@ function wp_network_dashboard_right_now() {
<p class="youhave"><?php echo $sentence; ?></p>
<?php do_action( 'wpmuadminresult', '' ); ?>
<form name="searchform" action="<?php echo network_admin_url('users.php'); ?>" method="get">
<form action="<?php echo network_admin_url('users.php'); ?>" method="get">
<p>
<input type="search" name="s" value="" size="30" id="all-user-search-input" />
<input type="search" name="s" value="" size="30" autocomplete="off" />
<?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
</p>
</form>
<form name="searchform" action="<?php echo network_admin_url('sites.php'); ?>" method="get">
<form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
<p>
<input type="search" name="s" value="" size="30" id="site-search-input" />
<input type="search" name="s" value="" size="30" autocomplete="off" />
<?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
</p>
</form>

View File

@ -1,11 +0,0 @@
jQuery( function($) {
var isRTL = !! ( 'undefined' != typeof isRtl && isRtl );
$( '#site-search-input' ).autocomplete({
source: ajaxurl + '?action=autocomplete-site',
delay: 500,
minLength: 2,
position: isRTL ? { my: 'right top', at: 'right bottom', offset: '0, -1' } : { offset: '0, -1' },
open: function(e, ui) { $(this).addClass('open'); },
close: function(e, ui) { $(this).removeClass('open'); }
});
});

View File

@ -1 +0,0 @@
jQuery(function(b){var a=!!("undefined"!=typeof isRtl&&isRtl);b("#site-search-input").autocomplete({source:ajaxurl+"?action=autocomplete-site",delay:500,minLength:2,position:a?{my:"right top",at:"right bottom",offset:"0, -1"}:{offset:"0, -1"},open:function(d,c){b(this).addClass("open")},close:function(d,c){b(this).removeClass("open")}})});

View File

@ -1,38 +0,0 @@
jQuery( function($) {
var id = typeof( current_site_id ) != 'undefined' ? '&site_id=' + current_site_id : '',
isRTL = !! ( 'undefined' != typeof isRtl && isRtl ),
position = isRTL ? { my: 'right top', at: 'right bottom', offset: '0, -1' } : { offset: '0, -1' },
open = function(e, ui) {
$(this).addClass('open');
},
close = function(e, ui) {
$(this).removeClass('open');
};
$( '#adduser-email, #newuser' ).autocomplete({
source: ajaxurl + '?action=autocomplete-user&autocomplete_type=add' + id,
delay: 500,
minLength: 2,
position: position,
open: open,
close: close
});
$( '#user-search-input' ).autocomplete({
source: ajaxurl + '?action=autocomplete-user&autocomplete_type=search' + id,
delay: 500,
minLength: 2,
position: position,
open: open,
close: close
});
$( '#all-user-search-input' ).autocomplete({
source: ajaxurl + '?action=autocomplete-user&autocomplete_type=search-all' + id,
delay: 500,
minLength: 2,
position: position,
open: open,
close: close
});
});

View File

@ -0,0 +1,13 @@
(function($) {
var id = 'undefined' !== typeof current_site_id ? '&site_id=' + current_site_id : '';
$(document).ready( function() {
$( '.wp-suggest-user' ).autocomplete({
source: ajaxurl + '?action=autocomplete-user&autocomplete_type=add' + id,
delay: 500,
minLength: 2,
position: ( 'undefined' !== typeof isRtl && isRtl ) ? { my: 'right top', at: 'right bottom', offset: '0, -1' } : { offset: '0, -1' },
open: function() { $(this).addClass('open'); },
close: function() { $(this).removeClass('open'); }
});
});
})(jQuery);

View File

@ -172,7 +172,7 @@ $parent_file = 'sites.php';
$submenu_file = 'sites.php';
if ( ! wp_is_large_network( 'users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) )
wp_enqueue_script( 'user-search' );
wp_enqueue_script( 'user-suggest' );
require('../admin-header.php'); ?>
@ -267,7 +267,7 @@ endif; ?>
<table class="form-table">
<tr>
<th scope="row"><?php _e( 'Username' ); ?></th>
<td><input type="text" class="regular-text" name="newuser" id="newuser" /></td>
<td><input type="text" class="regular-text wp-suggest-user" name="newuser" id="newuser" /></td>
</tr>
<tr>
<th scope="row"><?php _e( 'Role'); ?></th>

View File

@ -282,9 +282,6 @@ if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty(
$wp_list_table->prepare_items();
if ( ! wp_is_large_network( 'sites' ) )
wp_enqueue_script( 'site-search' );
require_once( '../admin-header.php' );
?>

View File

@ -245,9 +245,6 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
);
if ( ! wp_is_large_network( 'users' ) )
wp_enqueue_script( 'user-search' );
require_once( '../admin-header.php' );
if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {

View File

@ -180,7 +180,7 @@ wp_enqueue_script('user-profile');
if ( is_multisite() && current_user_can( 'promote_users' ) && ! wp_is_large_network( 'users' )
&& ( is_super_admin() || apply_filters( 'autocomplete_users_for_site_admins', false ) )
) {
wp_enqueue_script( 'user-search' );
wp_enqueue_script( 'user-suggest' );
}
require_once( 'admin-header.php' );
@ -269,7 +269,7 @@ if ( is_multisite() ) {
<table class="form-table">
<tr class="form-field form-required">
<th scope="row"><label for="adduser-email"><?php echo $label; ?></label></th>
<td><input name="email" type="text" id="adduser-email" value="" /></td>
<td><input name="email" type="text" id="adduser-email" class="wp-suggest-user" value="" /></td>
</tr>
<tr class="form-field">
<th scope="row"><label for="adduser-role"><?php _e('Role'); ?></label></th>

View File

@ -339,12 +339,6 @@ default:
exit;
}
if ( is_multisite() && current_user_can( 'promote_users' ) && ! wp_is_large_network( 'users' )
&& ( is_super_admin() || apply_filters( 'autocomplete_users_for_site_admins', false ) )
) {
wp_enqueue_script( 'user-search' );
}
include('./admin-header.php');
$messages = array();

View File

@ -267,9 +267,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter' ), false, 1 );
$scripts->add( 'user-search', "/wp-admin/js/user-search$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
$scripts->add( 'site-search', "/wp-admin/js/site-search$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
$scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
$scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 );