From 3ebea2f21859c6333dbd5d87f7746940a498e167 Mon Sep 17 00:00:00 2001 From: nacin Date: Tue, 5 Jun 2012 18:51:33 +0000 Subject: [PATCH] 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 --- wp-admin/admin-ajax.php | 2 +- wp-admin/includes/ajax-actions.php | 24 ------------ wp-admin/includes/dashboard.php | 14 ++----- wp-admin/js/site-search.dev.js | 11 ------ wp-admin/js/site-search.js | 1 - wp-admin/js/user-search.dev.js | 38 ------------------- wp-admin/js/user-suggest.dev.js | 13 +++++++ .../js/{user-search.js => user-suggest.js} | 0 wp-admin/network/site-users.php | 4 +- wp-admin/network/sites.php | 3 -- wp-admin/network/users.php | 3 -- wp-admin/user-new.php | 4 +- wp-admin/users.php | 6 --- wp-includes/script-loader.php | 4 +- 14 files changed, 23 insertions(+), 104 deletions(-) delete mode 100644 wp-admin/js/site-search.dev.js delete mode 100644 wp-admin/js/site-search.js delete mode 100644 wp-admin/js/user-search.dev.js create mode 100644 wp-admin/js/user-suggest.dev.js rename wp-admin/js/{user-search.js => user-suggest.js} (100%) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index c20727b08a..099a66f64a 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -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( diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 2fc8ebb302..9666ce7983 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -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. */ diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index b284f05dc2..6e7d5f0d07 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -414,12 +414,6 @@ function wp_network_dashboard_right_now() { if ( current_user_can('create_users') ) $actions['create-user'] = '' . __( 'Create a New User' ) . ''; - 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() {

-
+

- + 'submit_users' ) ); ?>

-
+

- + 'submit_sites' ) ); ?>

diff --git a/wp-admin/js/site-search.dev.js b/wp-admin/js/site-search.dev.js deleted file mode 100644 index e47d7a4c99..0000000000 --- a/wp-admin/js/site-search.dev.js +++ /dev/null @@ -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'); } - }); -}); diff --git a/wp-admin/js/site-search.js b/wp-admin/js/site-search.js deleted file mode 100644 index 04c76d26a0..0000000000 --- a/wp-admin/js/site-search.js +++ /dev/null @@ -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")}})}); \ No newline at end of file diff --git a/wp-admin/js/user-search.dev.js b/wp-admin/js/user-search.dev.js deleted file mode 100644 index ce3b63a799..0000000000 --- a/wp-admin/js/user-search.dev.js +++ /dev/null @@ -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 - }); -}); diff --git a/wp-admin/js/user-suggest.dev.js b/wp-admin/js/user-suggest.dev.js new file mode 100644 index 0000000000..0bcfada4ba --- /dev/null +++ b/wp-admin/js/user-suggest.dev.js @@ -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); \ No newline at end of file diff --git a/wp-admin/js/user-search.js b/wp-admin/js/user-suggest.js similarity index 100% rename from wp-admin/js/user-search.js rename to wp-admin/js/user-suggest.js diff --git a/wp-admin/network/site-users.php b/wp-admin/network/site-users.php index 0289629c35..58796b258d 100644 --- a/wp-admin/network/site-users.php +++ b/wp-admin/network/site-users.php @@ -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; ?> - + diff --git a/wp-admin/network/sites.php b/wp-admin/network/sites.php index 2b12c599c0..4bee9e1afd 100644 --- a/wp-admin/network/sites.php +++ b/wp-admin/network/sites.php @@ -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' ); ?> diff --git a/wp-admin/network/users.php b/wp-admin/network/users.php index a6bdfc74e6..98246c3fbf 100644 --- a/wp-admin/network/users.php +++ b/wp-admin/network/users.php @@ -245,9 +245,6 @@ get_current_screen()->set_help_sidebar( '

' . __('Support Forums') . '

' ); -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'] ) ) { diff --git a/wp-admin/user-new.php b/wp-admin/user-new.php index 4eff50eacb..3119eb5720 100644 --- a/wp-admin/user-new.php +++ b/wp-admin/user-new.php @@ -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() ) {
- + diff --git a/wp-admin/users.php b/wp-admin/users.php index cbd808e0a0..f26255fca6 100644 --- a/wp-admin/users.php +++ b/wp-admin/users.php @@ -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(); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 84a3671027..49e30a98a4 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -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 );