Skip to content

Instantly share code, notes, and snippets.

Last active May 14, 2023 03:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Simple dashboard widget for listing WordPress multisite sites, and accompanying shortcode for the front end.
Plugin Name: Network Lister
Plugin URI:
Update URI: network-lister
Description: simple dashboard widget for listing network sites
Version: 0.0.5
Author: WebAware
Author URI:
copyright (c) 2018-2023 WebAware Pty Ltd
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace webaware\network_lister;
if (!defined('ABSPATH')) {
* get a list of all sites on the network
function get_list(bool $for_admin) : string {
$output = '';
$current_site_id = get_current_blog_id();
$sites = get_sites();
if (is_array($sites)) {
$list = [];
$template = $for_admin ? '<li><a href="%s/wp-admin/"%s>%s — %s</a></li>' : '<li><a href="%s/"%s>%s — %s</a></li>';
foreach ($sites as $site) {
$details = get_blog_details($site->blog_id);
$style = $current_site_id == $site->blog_id ? ' style="font-weight:bold"' : '';
$list[$details->blogname] = sprintf($template,
uksort($list, 'strcasecmp');
$output = '<ul>' . implode('', $list) . '</ul>';
return $output;
* show list widget on admin dashboard
function show_lister_widget() : void {
echo get_list(true);
* create the new dashboard widget
function add_lister_widget() : void {
wp_add_dashboard_widget('network-lister', 'Network List', __NAMESPACE__ . '\\show_lister_widget');
add_action('wp_dashboard_setup', __NAMESPACE__ . '\\add_lister_widget');
add_action('wp_network_dashboard_setup', __NAMESPACE__ . '\\add_lister_widget');
* add shortcode for network list
add_shortcode('network_lister', function() : string {
return get_list(false);
* show the current site ID on every page footer
add_filter('admin_footer_text', function(string $footer_text) : string {
$footer_text .= ' &bull; blog_id = ' . get_current_blog_id();
return $footer_text;
}, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment