[wp-hackers] Users for each blog in Multi-Site?

Paul Menard paul at codehooligans.com
Wed May 9 18:11:37 UTC 2012


The key is that under MS a user can have access to more than one blog. There are two elements in the usermeta table to look into: 

1. 'primary_blog' - As the key_name implies this is the user's primary blog. Will only contain one blog ID.

2. As for when a user can access other blogs the key is in the capabilities. If you view the usermeta table for a user you will see a record with a meta_key like 'wp_4_capabilities'. This means the user has access to blog 4. A given user may have multiple 'wp_XX_capabilities' rows where 'XX' is the blog ID. You can access this information simply by using the MS function get_blogs_of_user($user_id) see wp-includes/user.php line 652. This will return a list of blogs for the user. There is also a compliment function is_user_member_of_blog($user_id, $blog_id) for a simple user check. 

2b. There is also a handy function get_blog_details($blog_id) to obtain the blog details. Better than a direct query on the blogs table. 

Hope this helps. 


On May 9, 2012, at 1:59 PM, Mike Walsh wrote:

> I've been poking through my mutli-site database in an effort to understand
> where the information that connects a user to each specific blog is stored.
> My search through the Codex and Support Forums hasn't yielded anything
> either.  I have a plugin I am trying to ensure works correctly with WPMS
> and it looks at the users.  Right now I am showing all of the users
> registered on the network and not just the ones assigned to the specific
> blog and I am not sure how to limit my list to the subset of users who have
> been assigned access to the blog.
> Thanks,
> Mike
> -- 
> Mike Walsh - mpwalsh8 at gmail.com
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list