Improve information displayed in a network's sites list table

* Better support for arbitrary domain/path combinations by displaying the URL in the primary column rather than Path or Domain.
* Show a cached count of total users per site as a more useful data point rather than the first 5 users.
* Clear that cached count of users for a site when a user is added to the site via `add_user_to_blog()`.

Props @ocean90.
Fixes #32434.

Built from https://develop.svn.wordpress.org/trunk@32718


git-svn-id: http://core.svn.wordpress.org/trunk@32688 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jeremy Felt 2015-06-10 06:50:25 +00:00
parent 005d937ce2
commit 93ff65e677
7 changed files with 43 additions and 27 deletions

View File

@ -259,7 +259,7 @@ table.fixed {
} }
.fixed .column-posts { .fixed .column-posts {
width: 74px; width: 74px;
} }
.fixed .column-comment .comment-author { .fixed .column-comment .comment-author {
@ -1510,6 +1510,15 @@ div.action-links,
background: #fecac2; background: #fecac2;
} }
.sites.fixed .column-lastupdated,
.sites.fixed .column-registered {
width: 20%;
}
.sites.fixed .column-users {
width: 80px;
}
/* =Media Queries /* =Media Queries
-------------------------------------------------------------- */ -------------------------------------------------------------- */

View File

@ -259,7 +259,7 @@ table.fixed {
} }
.fixed .column-posts { .fixed .column-posts {
width: 74px; width: 74px;
} }
.fixed .column-comment .comment-author { .fixed .column-comment .comment-author {
@ -1510,6 +1510,15 @@ div.action-links,
background: #fecac2; background: #fecac2;
} }
.sites.fixed .column-lastupdated,
.sites.fixed .column-registered {
width: 20%;
}
.sites.fixed .column-users {
width: 80px;
}
/* =Media Queries /* =Media Queries
-------------------------------------------------------------- */ -------------------------------------------------------------- */

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -111,10 +111,11 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
} elseif ( $order_by == 'lastupdated' ) { } elseif ( $order_by == 'lastupdated' ) {
$query .= ' ORDER BY last_updated '; $query .= ' ORDER BY last_updated ';
} elseif ( $order_by == 'blogname' ) { } elseif ( $order_by == 'blogname' ) {
if ( is_subdomain_install() ) if ( is_subdomain_install() ) {
$query .= ' ORDER BY domain '; $query .= ' ORDER BY domain ';
else } else {
$query .= ' ORDER BY path '; $query .= ' ORDER BY path ';
}
} elseif ( $order_by == 'blog_id' ) { } elseif ( $order_by == 'blog_id' ) {
$query .= ' ORDER BY blog_id '; $query .= ' ORDER BY blog_id ';
} else { } else {
@ -182,17 +183,17 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
* @return array * @return array
*/ */
public function get_columns() { public function get_columns() {
$blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
$sites_columns = array( $sites_columns = array(
'cb' => '<input type="checkbox" />', 'cb' => '<input type="checkbox" />',
'blogname' => $blogname_columns, 'blogname' => __( 'URL' ),
'lastupdated' => __( 'Last Updated' ), 'lastupdated' => __( 'Last Updated' ),
'registered' => _x( 'Registered', 'site' ), 'registered' => _x( 'Registered', 'site' ),
'users' => __( 'Users' ) 'users' => __( 'Users' ),
); );
if ( has_filter( 'wpmublogsaction' ) ) if ( has_filter( 'wpmublogsaction' ) ) {
$sites_columns['plugins'] = __( 'Actions' ); $sites_columns['plugins'] = __( 'Actions' );
}
/** /**
* Filter the displayed site columns in Sites list table. * Filter the displayed site columns in Sites list table.
@ -261,7 +262,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
} }
echo "<tr{$class}>"; echo "<tr{$class}>";
$blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path']; $blogname = $blog['domain'] . $blog['path'];
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
@ -322,22 +323,18 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
break; break;
case 'users': case 'users':
$blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) ); if ( ! $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' ) ) {
if ( is_array( $blogusers ) ) { $blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) );
$blogusers_warning = ''; $user_count = count( $blog_users );
if ( count( $blogusers ) > 5 ) { unset( $blog_users );
$blogusers = array_slice( $blogusers, 0, 5 ); wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS );
$blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
}
foreach ( $blogusers as $user_object ) {
echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
if ( 'list' != $mode )
echo '( ' . $user_object->user_email . ' )';
echo '<br />';
}
if ( $blogusers_warning != '' )
echo '<strong>' . $blogusers_warning . '</strong><br />';
} }
printf(
'<a href="%s">%s</a>',
esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
number_format_i18n( $user_count )
);
break; break;
case 'plugins': case 'plugins':

View File

@ -204,6 +204,7 @@ function add_user_to_blog( $blog_id, $user_id, $role ) {
*/ */
do_action( 'add_user_to_blog', $user_id, $role, $blog_id ); do_action( 'add_user_to_blog', $user_id, $role, $blog_id );
wp_cache_delete( $user_id, 'users' ); wp_cache_delete( $user_id, 'users' );
wp_cache_delete( $blog_id . '_user_count', 'blog-details' );
restore_current_blog(); restore_current_blog();
return true; return true;
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-32717'; $wp_version = '4.3-alpha-32718';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.