Multisite – only allow one site per user

Hi there,

I’m using WordPress multisite and I want to limit only one single site for one single user, how can I do that?

Thanks

Leo

  • Ash
    • WordPress Hacker

    Hello @leo

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    Would you please try adding the following code in your theme’s functions.php:

    function ds_one_blog_only($active_signup) {
    // get the array of the current user's blogs
    $blogs = get_blogs_of_user( get_current_user_id() );
    // all users may be members of blog 1 so remove it from the count, could be a "Dashboard" blog as well
    if ($blogs["1"]) unset($blogs["1"]);
    //if the user still has blogs, disable signup else continue with existing active_signup rules at SiteAdmin->Options
    $n = count($blogs);
    if($n == 1) {
    $active_signup = 'none';
    echo '';
    } elseif($n > 1) {
    $active_signup = 'none';
    echo '';
    } else {
    $active_signup = $active_signup;
    }
    return $active_signup; // return "all", "none", "blog" or "user"
    }
    add_filter('wpmu_active_signup', 'ds_one_blog_only');

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name ‘mu-plugins’. If there is no folder in that name, then create a folder, name it ‘mu-plugins’, create a file inside that, give any name you like and paste the code in there. You don’t need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always.

    Please let me know if you find this is helpful, or if you have any further questions.

    Cheers

    Ash

  • Leo
    • WPMU DEV Initiate

    Hi Ashok,

    Thanks for your prompt and professional response. the code works well.

    However, I have another question that needs your help:

    The same situation,:

    I’m using WordPress multisite, the main site domain name is aaa.com

    I want that anybody who clicks the (register)signup page from the main site domain aaa.com is able to apply for a new site but if anybody clicks the signup page from the sub-domains or domains rather than aaa.com can not apply for a new site but only can register the user account.

    Please help.

    Thanks

    Leo

  • Ash
    • WordPress Hacker

    Hi there

    I am referring to some plugins, please check those. Also, keep a backup of all your files, including database as this works with user role so if something goes wrong, you can roll back :slight_smile:

    http://wordpress.org/plugins/multisite-user-management/

    http://wordpress.org/plugins/join-my-multisite/ (recommended)

    http://wordpress.org/plugins/wp-members/

    Please let me know if you find this is helpful, or if you have any further questions.

    Cheers

    Ash

  • Leo
    • WPMU DEV Initiate

    Hi Ashok,

    Actually I knew about the three plugins and I’ve tried them. The “”join-my-multisite” one looks good but it’s actually very weak.

    I will probably write some codes by myself.

    Thanks anyway and closing the ticket.

    Leo

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.