Skip to content

Commit 461e246

Browse files
committed
Autocomplete site names in Network Admin. More user completion areas. props Japh, DrewAPicture. see #19810.
git-svn-id: https://develop.svn.wordpress.org/trunk@20279 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e077371 commit 461e246

14 files changed

Lines changed: 108 additions & 11 deletions

wp-admin/admin-ajax.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

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

4242
$core_actions_post = array(

wp-admin/css/wp-admin.dev.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ ul#add-to-blog-users {
900900

901901
.ui-autocomplete li a.ui-state-hover {
902902
background-color: #f0f0b8;
903+
cursor: pointer;
903904
}
904905

905906
/*------------------------------------------------------------------------------

wp-admin/includes/ajax-actions.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,26 @@ function wp_ajax_autocomplete_user() {
160160

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'] ) )
165171
$id = absint( $_REQUEST['site_id'] );
166172
else
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
) );
177185

@@ -206,6 +214,35 @@ function wp_ajax_dashboard_widgets() {
206214
wp_die();
207215
}
208216

217+
function 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 ) );
244+
}
245+
209246
/*
210247
* Ajax helper.
211248
*/

wp-admin/includes/dashboard.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,23 @@ function wp_network_dashboard_right_now() {
416416
if ( current_user_can('create_users') )
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();
421438

@@ -440,14 +457,14 @@ function wp_network_dashboard_right_now() {
440457

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>
446463
</form>
447464

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>
453470
</form>

wp-admin/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
'<p>' . __( '<a href="http://codex.wordpress.org/Dashboard_Screen" target="_blank">Documentation on Dashboard</a>' ) . '</p>' .
8989
'<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
9090
);
91-
91+
9292
include (ABSPATH . 'wp-admin/admin-header.php');
9393

9494
$today = current_time('mysql', 1);

wp-admin/js/site-search.dev.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
jQuery( function($) {
2+
$( '#site-search-input' ).autocomplete({
3+
source: ajaxurl + '?action=autocomplete-site',
4+
delay: 500,
5+
minLength: 2
6+
});
7+
});

wp-admin/js/site-search.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp-admin/js/user-search.dev.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@ jQuery( function($) {
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-
});
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,
18+
delay: 500,
19+
minLength: 2
20+
});
21+
});

wp-admin/js/user-search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp-admin/network/site-users.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
$parent_file = 'sites.php';
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' ) )
174+
if ( ! wp_is_large_network( 'users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) )
175175
wp_enqueue_script( 'user-search' );
176176

177177
require('../admin-header.php'); ?>

0 commit comments

Comments
 (0)