Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created October 4, 2012 09:51
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bueltge/3832632 to your computer and use it in GitHub Desktop.
Save bueltge/3832632 to your computer and use it in GitHub Desktop.
View Blog and User ID in WordPress Multisite
<?php
/**
* Plugin Name: Add Blog and User ID on Network
* Plugin URI: http://wpengineer.com/2188/view-blog-id-in-wordpress-multisite/
* Description: View Blog and User ID in WordPress Multisite
* Version: 1.0.0
* Author: Frank Bültge
* Author URI: http://bueltge.de
* License: GPLv3
*/
! defined( 'ABSPATH' ) and exit;
class fb_add_blog_id {
public static function init() {
$class = __CLASS__ ;
if ( empty( $GLOBALS[ $class ] ) )
$GLOBALS[ $class ] = new $class;
}
public function __construct() {
// add blog id
add_filter( 'wpmu_blogs_columns', array( $this, 'get_id' ) );
add_action( 'manage_sites_custom_column', array( $this, 'get_blog_id' ), 10, 2 );
// add user id
add_filter( 'manage_users-network_columns', array( $this, 'get_id' ) );
add_action( 'manage_users_custom_column', array( $this, 'get_user_id' ), 10, 3 );
add_action( 'admin_print_styles-sites.php', array( $this, 'add_style' ) );
add_action( 'admin_print_styles-users.php', array( $this, 'add_style' ) );
}
public function get_blog_id( $column_name, $blog_id ) {
if ( 'object_id' === $column_name )
echo (int) $blog_id;
return $column_name;
}
public function get_user_id( $value, $column_name, $user_id ) {
if ( 'object_id' === $column_name )
echo (int) $user_id;
}
// Add in a column header
public function get_id( $columns ) {
$columns['object_id'] = __('ID');
return $columns;
}
public function add_style() {
echo '<style>#object_id { width:7%; }</style>';
}
}
add_action( 'plugins_loaded', array( 'fb_add_blog_id', 'init' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment