View Blog ID in WordPress Multisite

When you work quite a bit with WordPress Multisites, sometimes you need the IDs for some functions or Plugins. The easiest way is via the hover effect with your mouse or you use a little code snippet to add a column with the ID in the table view.



The following code belongs into a Plugin and should be placed in the folder mu-plugins.

class Add_Blog_ID {
	
	public static function init() {
		$class = __CLASS__ ;

		if ( empty( $GLOBALS[ $class ] ) )
			$GLOBALS[ $class ] = new $class;
	}
	
	public function __construct() {
		
		add_filter( 'wpmu_blogs_columns', array( $this, 'get_id' ) );
		add_action( 'manage_sites_custom_column', array( $this, 'add_columns' ), 10, 2 );
		add_action( 'manage_blogs_custom_column', array( $this, 'add_columns' ), 10, 2 );
		add_action( 'admin_footer', array( $this, 'add_style' ) );
	}
	
	public function add_columns( $column_name, $blog_id ) {
		
		if ( 'blog_id' === $column_name )
			echo $blog_id;
		
		return $column_name;
	}

	// Add in a column header
	public function get_id( $columns ) {
		
		$columns['blog_id'] = __('ID');
		
		return $columns;
	}
	
	public function add_style() {
		
		echo '';
	}
}
add_action( 'init', array( 'Add_Blog_ID', 'init' ) );

Alternative you can use the follow plugin with this feature and also list the user ID on network view. You can download the plugin in this GIST 3832632.


Posted

in

by

Comments

10 responses to “View Blog ID in WordPress Multisite”

  1. Michael Caputo Avatar

    Hey there, i’d really like to use this, but I don’t understand this line: The following code belongs into a Plugin and should be placed in the folder mu-plugins.

    Please clarify?

  2. Brian Krogsgard Avatar

    Hey Michael,

    The mu-plugins folder is one that operates similarly to the plugins folder, but any plugin in it is automatically activated across your network. It stands for “must-use”.

    It is not a folder that comes with your install, so you need to manually create it.

    You can read more about it on Justin Tadlock’s article

  3. Frank Avatar

    @brian: thanks for this great comment to Michaels questions.

  4. Brian Krogsgard Avatar

    @frank

    No problem : )

    And nice snippet. Bookmarked. I bet I’ll be needing this in an upcoming project.

  5. Michael Caputo Avatar

    Thanks for following up. Just a FYI, i didn’t recieve a notification that you answered my question even thought I clicked the “Notify me of followup comments” button on the form.. It may have gone to my spam, but just so you know 😀

  6. sebastien Avatar
    sebastien

    i don’t understand… there is already a colum with ID : http://archiparmentier.com/admin.jpg

  7. […] https://wpengineer.com/2188/view-blog-id-in-wordpress-multisite/ 08 April 2011 5:08pm – Andra bloggar – Tips & knep – WordPress « Använd Gmail som hårddisk […]

  8. […] This trick was originally published by WP Engineer. […]

  9. Frank Avatar

    @sebastian: this is not default; maybe you have active a domain-mapping plugin?

  10. sebastien Avatar
    sebastien

    yes franck, that’s it, you’re right !