WordPress.org

Ready to get started?Download WordPress

Forums

Separate User Bases? (7 posts)

  1. zacclay
    Member
    Posted 1 year ago #

    Is there any way using multisite and any other combination of plugins to make it so that a user only has access to see the site that they are a member of?

    In particular:
    I have a wordpress multi-site install and then installed http://buddydev.com/plugins/buddypress-multi-network/ so that I could have multiple buddypress networks.

    The problem is that I don’t want a user to be able to join any network they want.

    For example, I have 1.[domain].com and 2.[domain].com. Each one has its own buddypress network. The problem is, even if I have the private buddypress plugin installed, if someone has an account on 1.[domain].com, then they can just login on 2.[domain].com.

    I want to make it so that the user on 1.[domain].com would need to request access to 2.[domain].com in order to use it.

  2. Untested.

    <?php
    
    /*
    Plugin Name: Block Users
    Description: Only allow members to see sites.
    */
    
    function zac_stop_users( ) {
        global $current_user, $blog_id;
    
        if( !is_user_logged_in() || !is_user_member_of_blog() && ($blog_id == 2) ) {
            // do something ...
        }
    }
    
    add_action( 'wp' , 'zac_stop_users' , 10);

    In theory this will check if someone is not logged in and not a member of the blog AND the blog is #2 (the one you want to keep private).

    Where I put // do something is where you can decide what to do. Redirect them to another page or... whatever.

  3. zacclay
    Member
    Posted 1 year ago #

    Wow, thanks!

    I will try this out later when I get a chance. If I'm understanding this, it would block someone from a particular site if they are not a member right? What if I had hundreds of blogs and only wanted people to be able to login to the one they are a member of?

  4. Then it's slightly more complicated. You would have to have at least ONE site where everyone can see (I would pick your main domain, so site #1).

    Change $blog_id == 2 to $blog_id != 1 and that should do it. If they go to Site #1, everything's fine :)

  5. zacclay
    Member
    Posted 1 year ago #

    Perfect, thanks again!

  6. zacclay
    Member
    Posted 1 year ago #

    sorry, one more stupid question, would I just paste that into a .php file and then upload it to the mu-plugins directory?

  7. Yes :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.