User Management in Multisite

Hi,

I am working on setting up a SaaS on a multisite. I would like that users that register on Site1.xxx.com are not automatically registered to site2.xxx.com – they would need to register there separately. While I am aware that user table for a multisite is common – i believe this is possible?

can you please guide?

thanks

  • Adam
    • Support Gorilla

    Hello ajacks

    I hope you’re well today!

    That’s actually exactly how it works “out of the box”. The “user base” is common in that sense that basic account data is common (e.g. e-mail) but the user who registers on “subsite A” isn’t automatically added as a user on “subsite B”.

    In WordPress by default (assuming there’s no modifications to that flow via custom code or some additional plugin) such user – if logged in to “subsite A”, will still remain logged in on “subsite B” at the “subscriber” level, though it’s kind of “virtual” user role. The user is not on the list of users of “subsite B”.

    If you have any follow-up questions, let me know please and I’ll be happy to assist you further.

    Best regards,

    Adam

  • ajacks
    • WPMU DEV Initiate

    Hi Adam,

    Thank you for your reply! The scenario you explained is exactly my issue :slight_smile:

    I am working on providing an eCommerce platform to independent service providers who don’t have tech skills/patience… now since it is a multi-site user logged in on Site A, is automatically logged in on Site B…. can this be avoided? It is quite possible that customers of Site A will go to Site B and find themselves auto logged in (Using domain mapping they wont be aware they are on the same platform)

    How do I make it so

    1) User1 registers and logs in to Site A

    2) User1 visits Site B but is not shown to be logged in… and has to register there to login and use services

    I understand users share a common table in Multisite but its confusing for users who are registered on Site A to know they are auto registered on Site B without their explicit permission…..

    Thanks

  • Adam
    • Support Gorilla

    Hello ajacks

    If you are using domain mapping that’s built into WP core (so you’re just setting individual domains for sub-sites), for the sites with mapped domains it won’t be an issue at all – they will not be automatically logged in.

    The same if you’re using a Domain Mapping plugin and have

    – sites set to redirect to mapped domain

    – login an admin area in plugin settings set to use mapped domains

    – and “cross-domain auto login” disabled in Domain Mapping plugin settings

    In both these cases user won’t be logged in to the sites over mapped domains. They’ll have to log in separately so they’ll also will have to be users of these sites.

    It will, however, still be an issue on sites without mapped domains. You can try this code though:

    <?php

    function my_check_user_blogs( $user_login, $user ) {
    $current_site = get_current_site();
    if ( ! is_user_member_of_blog( $user->id, $current_site->id ) ) {
    wp_logout();
    }
    }

    add_action('wp_login', 'my_check_user_blogs', 10, 2);

    You can add it to the site as mu-plugin and see if it helps:

    – create an empty file with a .php extension (e.g. my-non-user-logout.php)

    – copy and paste the code into it

    – upload it to the “/wp-content/mu-plugins” folder of your Multisite install; if there’s no such folder there, just create an empty one.

    Make sure to clear all caches before testing and see if it works. Note: deleting the file will immediately bring everything back to as it currently is.

    Best regards,

    Adam