Network Overview Widget in the Network Dashboard
Adds a widget to the Network Admin dashboard with totals for sites, users, archived, spam and deleted sites, and the five newest sites.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_action( 'wp_network_dashboard_setup', function () {
wp_add_dashboard_widget( 'wpide_network_overview', __( 'Network overview' ), function () {
$rows = array(
__( 'Sites' ) => get_blog_count(),
__( 'Users' ) => get_user_count(),
__( 'Archived' ) => get_sites( array( 'archived' => 1, 'count' => true ) ),
__( 'Spam' ) => get_sites( array( 'spam' => 1, 'count' => true ) ),
__( 'Deleted' ) => get_sites( array( 'deleted' => 1, 'count' => true ) ),
);
echo '<table class="widefat striped"><tbody>';
foreach ( $rows as $label => $value ) {
echo '<tr><td>' . esc_html( $label ) . '</td><td style="text-align:right"><strong>' . esc_html( number_format_i18n( (int) $value ) ) . '</strong></td></tr>';
}
echo '</tbody></table>';
$newest = get_sites( array( 'number' => 5, 'orderby' => 'registered', 'order' => 'DESC' ) );
if ( $newest ) {
echo '<h3 style="margin-top:1em">' . esc_html__( 'Newest sites' ) . '</h3><ul>';
foreach ( $newest as $site ) {
printf(
'<li><a href="%1$s">%2$s</a> <span style="color:#646970">%3$s</span></li>',
esc_url( network_admin_url( 'site-info.php?id=' . (int) $site->blog_id ) ),
esc_html( $site->blogname ? $site->blogname : $site->domain . $site->path ),
esc_html( mysql2date( get_option( 'date_format' ), $site->registered ) )
);
}
echo '</ul>';
}
} );
} );
Notes
Counts come from WordPress's own cached network counts and a single sites query.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.