Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a is_user_logged_in() function for Wordpress MU / Multisite (3.0+) where I can add in the network site ID like is_user_logged_in(2) where 2 would be the site_id?

Update:

After a little digging I came up with the code below. Unfortunately it does not work.

//don't use this. does not work.
function mu_logged_in($blog_id){
    switch_to_blog($blog_id);
        $status = is_user_logged_in();
    restore_current_blog();
    return $status;
}

anu's answer and comments are good.

also, make sure you have the cookie domain set correctly in the wp-config.php file :)

share|improve this question
    
Can you explain the use case? –  Chip Bennett Jun 27 '11 at 14:22

1 Answer 1

up vote 8 down vote accepted

Yes, and no!

The way users work in a multisite scenario is that there is a single pool of users, who are then associated with blogs.

So, logged in status is common across all the blogs, but you can use is_blog_user($blog_id) to determine whether the current logged in user is a member of that blog. An example:

if (is_user_logged_in()) {
  if (is_blog_user(4)) echo "Current user is a member of blog 4";
}

Codex page for is_blog_user()

share|improve this answer
    
I had something a little different in mind. I've added to to the question, but I think yours is very useful, too. –  cwd Jun 27 '11 at 15:55
    
Your answer will probably return true for any logged in user, no matter which blog that user is a member of. –  anu Jun 27 '11 at 15:58
    
You're right. It still only works for the current blog. But you see what I was trying to get at? I have a blog that the user will not be logged into, but I want to display information if they are logged into a different blog in the network. Any ideas? –  cwd Jun 27 '11 at 16:24
    
You're missing the point. A user's logged in status is 'global' - ie once that user has logged in, then that user is logged into all blogs with 'subscriber' as the default role. –  anu Jun 27 '11 at 16:29
    
actually I had the cookie domain set up wrong. after I fixed that then your code worked very well. thanks! –  cwd Jun 28 '11 at 5:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.