Instantly share code, notes, and snippets.

Embed
What would you like to do?
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