10

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 :)

  • Can you explain the use case? – Chip Bennett Jun 27 '11 at 14:22
9

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()

  • 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
  • 3
    Small hint. The function is_blog_user() is deprecated and the new functions to get this data is is_user_member_of_blog( $user_id, $blog_id ). – bueltge Jul 23 '13 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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