Skip to content

Instantly share code, notes, and snippets.

@peterchester
Created February 3, 2015 20:51
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 peterchester/6bcbae502dc946bc8a63 to your computer and use it in GitHub Desktop.
Save peterchester/6bcbae502dc946bc8a63 to your computer and use it in GitHub Desktop.
show-blog-belongs-to.php
<?php
/*
Plugin Name: Show User's Blogs
Description: Adds a list of what blogs a user belongs to to the user table.
Version: 1.0
Author: Modern Tribe, Inc.
*/
if(!class_exists('Show_Blog_Belongs')) {
class Show_Blog_Belongs {
public function __construct() {
$this->addActions();
$this->addFilters();
}
private function addActions() {
add_action('edit_user_profile', array($this, 'showBlogsForUser'));
add_action('show_user_profile', array($this, 'showBlogsForUser'));
}
private function addFilters() {
}
/// CALLBACK
public function showBlogsForUser($user) {
if(is_admin()) {
$blogs = get_blogs_of_user($user->ID, true);
?>
<h3><?php _e('Sites'); ?></h3>
<ul id="sites-this-user-belongs-to">
<?php foreach($blogs as $key => $blog) { ?>
<li><a href="<?php esc_attr_e($blog->siteurl); ?>"><?php esc_html_e($blog->blogname); ?></a> &mdash; <a href="<?php esc_attr_e(trailingslashit($blog->siteurl)); ?>wp-admin/"><?php _e('Backend'); ?></a></li>
<?php } ?>
</ul>
<?php
}
}
}
global $Show_Blog_Belongs;
$Show_Blog_Belongs = new Show_Blog_Belongs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment