• Resolved jolijo

    (@jolijo)


    I’ve used <?php if (is_user_logged_in()) : ?> to restrict the access to some content so only logged in viewers can see it. It worked fine.

    But now I’v noticed that if someone is logged in on a subsite they also see the restricted content on the mainsite. And some of the subsites will have their own subscribers.

    Is there a way to only show this content to a specific group of users? Either make sure that users on other sites can’t see whats hidden in the “is_user_logged_in” or can what i’m looking for be done with a plugin?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    In place of
    <?php if (is_user_logged_in()) : ?>

    Try something like this to restrict content to the smaller group of network users that are members of the blog:

    <?php global $current_user, $blog_id;
    		if( is_user_member_of_blog( $current_user->id, $blog_id ) : ?>
    Thread Starter jolijo

    (@jolijo)

    Thanks, I’ll check out the plugins.

    David, I tried that but i didn’t get it to work any different since all users are members of the main site.
    Can I somehow change that code it so only members of a certain subsite can see the content if I put the code on the mainsite?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Yes, but it would involve heavy use of switch_to_blog() to make the per-blog calls, and that gets expensive (processor wise). There aren’t any ‘Network Wide Membership’ plugins yet, that I know of.

    jolijo,

    Change $blog_id and don’t set it to be global(which picks up the main blog id in your case) to restrict areas to members of certain other blog_id.

    For example, the following will test if user is member of blog_id 13

    <?php global $current_user;
    		if( is_user_member_of_blog( $current_user->id, '13' )) : ?>
    Thread Starter jolijo

    (@jolijo)

    Thank’s everyone for the help. I got it working now.

    Is there a way that i can display content of a page to a user that is logged in using username?

    Example:
    On the same page there are 5 lines of text:
    Line 1 with text
    Line 2 with text
    Line 3 with text
    Line 4 with text
    Line 5 with text

    Line 1 must only display if user 1 is logged in
    Line 2 must only display if user 2 us logged in
    Line 3 must only display if user 3 is logged in
    ect.

    Mvg,
    Avinash Bhageloe

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    avinashbhageloe – This topic was for restricting information for users between sites on a network. If you’re asking about THAT, follow the notes others made. If you just want to check ‘is logged in, then…’ you want either Widget Logic or the Members plugin by Justin Tadlock.

    If you need further help, make a NEW topic for yourself.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show content to a specific group of users’ is closed to new replies.