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]


Updating the site

Jotted by brajesh on February 6, 2010

Thank you everyone for your comments suggestions and everything. Recently, I have not been able to keep this blog updated, but from the mid of Feb, expect me to update it regularly.

So my question to you all, which of the plugins you would like to see updated. Other than the plugins I will go into details of wp 3.0 and buddypress.
Hope to see you guys here then :)

Thanks
Brajesh

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]



Get Adobe Flash playerPlugin by wpburn.com wordpress themes