Skip to content

Instantly share code, notes, and snippets.

@jamesmorrison
Last active January 2, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmorrison/4832f2e53c9246c0dd1c64dcf3007cb9 to your computer and use it in GitHub Desktop.
Save jamesmorrison/4832f2e53c9246c0dd1c64dcf3007cb9 to your computer and use it in GitHub Desktop.
Add the current site ID to the Admin Bar
<?php
/**
* Plugin Name: Admin Bar Site ID
* Description: Add the current site ID to the Admin Bar
* Version: 1.0.3
* Author: James Morrison
* Author URI: https://www.jamesmorrison.me/
**/
/**
* Security Check
*
* @since 1.0.0
**/
defined( 'ABSPATH' ) or die();
/**
* Add Site ID to admin bar
*
* @since 1.0.0
**/
add_action( 'admin_bar_menu',
function( $wp_admin_bar ) {
// Sanity check - this won't work if this isn't a multisite or if the user can't access network admin
if ( ! is_multisite() || ! current_user_can( 'manage_network' ) ) {
return;
}
// Get the Site ID
$_site_id = get_current_blog_id();
// Add the Node
$wp_admin_bar->add_node( [
"id" => "site-id",
"title" => "Site ID: $_site_id"
"href" => esc_url( add_query_arg( 'id', $_site_id, network_admin_url( 'site-info.php' ) ) ),
] );
},
999, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment