Get The List of all admins for a Blog on Wpmu

Jotted by brajesh on February 17, 2010

While working with my most recent plugin, I had an issue of finding all the admins of a blog on the wpmu network. after a couple of minutes, I implemented a small hack and It worked like charm.
So here you go.
Please Note, I have used User level, which is backward compatible and is there because of the legacy plugins support(according to codex), But this hack solves the problem to iterate through the Roles/capabilities.
So here is the code.


function get_admin_users_for_blog($blog_id) {
global $wpdb;
$key="wp_".$blog_id."_user_level";
return $wpdb->get_results($wpdb->prepare("SELECT user_id from $wpdb->usermeta AS um WHERE um.meta_key ='". $key."' AND um.meta_value=10"));
}

//and now call it

global $current_blog;

$admins=get_admin_users_for_blog($current_blog->blog_id);

//now you have $admins as an array of object, Just Iterate over it and do some stuff, well, I will just print out :D 

foreach($admins as $admin)

echo "ID:".$admin->ID;

///hmm you can use it for more productive reasons :) 

That’s the shortest code I could produce, I know, The better way will be to loop through the capabilities, but hacks are for you know :)

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]
If you enjoyed this post, make sure you subscribe to my RSS feed!
Grab my other free plugins here at wordpress Plugins repository.
We will keep coming with more informative tips,tricks,tutorials to keep you updated with wordpress/buddypress/wordpress mu regularly.If you want to help us,You can ,by spreading the words.We provide free and premium plugins/support for wordpress Mu,buddypress at a very low cost (starting with $30 for 3 months membership).If you or anyone you know,needs some real good plugins/themes for their wordpress Mu/buddypress powered site, Please refer them to http://BuddyDev.com.We will highly appreciate your support and keep coming with more useful and free stuffs.


One Response to “Get The List of all admins for a Blog on Wpmu”

  1. mercime says:

    Nice one. Working well. Thank you :-)


Leave a Reply


Get Adobe Flash playerPlugin by wpburn.com wordpress themes