WPMS Mapped Domain Login Issues

Hi WPMU Dev Staff / Community.

I have a Sub-domain WPMS with mapped domains. I followed steps 4-7 of this guide from Kinsta (note I do not host with Kinsta) to set it up natively:

https://kinsta.com/knowledgebase/wordpress-multisite-domain-mapping/

Everything is working fine, except that I am not auto logged in to all the sites in the network.

For example as a super admin, I login to the main site / primary site on the network (https://network.com/wp-login.php), everything works as expected and I can access the main site and network settings just fine. However, when I go to: My Sites->Network Admin->Sites and click on the "Dashboard" link under the mapped subsite I wish to access, it prompts me to login again, so I have to enter my super admin details again to access the subsite.

My questions are

1) Is this standard / expected behaviour (double login as described above), or should a super admin be logged in automatically to all subsites?

2) If this is standard is there a way to still allow super admins to only have to login to the main/primary site? If it's not standard behavior and something is wrong, any ideas where to look or what might be causing this to happen?

Further to the above, I was using the WPMU Dev Domain Mapping plugin using original domain for the admin and login pages, but due to issues with the customiser, I decided to use mapped domains for front and backend. When changing the settings in the Domain Mapping plugin to use mapped domains, this stopped the auto logins. Then I discovered via the Kinsta article that I don't need this plugin to map domains as WP now does this natively. I therefore do not wish to use the plugin. Is it possible that the Domain Mapping plugin has left some settings etc behind somewhere and is still interferring with the logins? I have already removed the sunrise file from wp-content folder, removed the "define('SUNRISE', 'on');" line from wp-config.php, disabled and deleted the plugin from the network.

One further thing is I did try to also login via the mapped subsite first (https://mapped-domain.com/wp-login.php) and then go to My Sites->Network Admin->Dashboard, but it also asks me to login in twice if I do it that way.

Very much appreciated

Thank you,
Dean

  • Ash
    • WordPress Hacker

    Hello Dean

    I know you mentioned you followed all the steps, but to double check, did you add the following in wp-config.php file?

    define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );

    And that goes before the "That's all, stop editing...." comment.

    Usually, this is default behavior of WPMS when you use mapped domain, that's why the above line needs to be added to define the cross domain login. But it can still fail.

    If you use our domain mapping plugin, then you have option to enable cross domain auto login which is handled by the plugin very easily. You mentioned, you were having problem with domain mapping plugin, would you please explain in detail so that we can take a look on this? If this is a bug from our end, we would be happy to fix this. Or if you already have a ticket for that issue, please share that URL.

    Have a nice day!

    Cheers,
    Ash

  • Dean
    • Design Lord, Child of Thor

    Hi Ash

    Yes I followed steps 4-7 exactly. I have the define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] ); line just before the "/* That's all, stop editing! Happy blogging. */" comment.

    Just to confirm what do you mean by this? "Usually, this is default behavior of WPMS when you use mapped domain, that's why the above line needs to be added to define the cross domain login. But it can still fail."

    Are you saying that the default WordPress behavior is to force the super admin to login twice if using mapped domains?

  • Dean
    • Design Lord, Child of Thor

    Also the Domain Mapping plugin is always got bugs. I had the "cross domain auto login" enabled and it only worked when using original domain and stopped working when I changed to mapped domain. If WordPress does the same thing natively then I don't want to use an extra plugin for no reason. Do you think there could be something the Domain Mapping plugin has done which has broken my site even after I have uninstalled?

  • Ash
    • WordPress Hacker

    Hello Dean

    Just to confirm what do you mean by this? "Usually, this is default behavior of WPMS when you use mapped domain, that's why the above line needs to be added to define the cross domain login. But it can still fail."

    Are you saying that the default WordPress behavior is to force the super admin to login twice if using mapped domains?

    Yes, this is default behavior. That's why it is suggested to add COOKIE_DOMAIN define.

    Also the Domain Mapping plugin is always got bugs. I had the "cross domain auto login" enabled and it only worked when using original domain and stopped working when I changed to mapped domain.

    That should not happen. Would you please install the domain mapping plugin again so that I can check and troubleshoot?

    Do you think there could be something the Domain Mapping plugin has done which has broken my site even after I have uninstalled?

    Nope, that's not possible. When a plugin is deactivated, none of its function is active unless it deals with roles, and that DB doesn't.

    The important advantage of using domain mapping plugin over the built-in feature is, you can map multiple domains to a single subsite. Also, you can define if the backend should be accessed using mapped domain or original domain etc.

    Let us know if you want us to check DM on your site :slight_smile: Have a nice day!

    Cheers,
    Ash

  • Dean
    • Design Lord, Child of Thor

    Hi Ash

    Thanks for your response. I am just a little confused by this part:

    Yes, this is default behavior. That's why it is suggested to add COOKIE_DOMAIN define.

    Does that mean that if I add the COOKIE_DOMAIN define to wp-config.php then the super admin will only need to login into the network (https://network.com/wp-login.php) and NOT have to login again to the mapped subsite when going to My Sites->Network Admin->Sites and clicking on a mapped subsite "Dashboard" link?

    Many thanks,
    Dean

  • Nithin
    • Support Wizard

    Hey Dean,

    Yes, you are right, once the COOKIE_DOMAIN is defined inside wp-config.php, then as a super admin you should be able to login to the dashboard of the subsites without any issue as you have mentioned, by going to the Sites page, and clicking on the "dashboard" link of the mapped subsite.

    Regards,
    Nithin

  • Nithin
    • Support Wizard

    Hi Dean,

    WordPress mulitisite doesn't quite support domain mapping out of the box. What Kasia meant is that the default workflow when mapped using Native WordPress, will get redirected to a login screen when a super admin tries to access the dashboard of a subsite, which is the correct behaviour.

    Using the code below, should help with cookies from not getting blocked, and allowing the user to access the dashboard, however as stated before, it might, or might not work effectively:

    define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );

    You can find the following article helpful:
    https://www.gilzow.com/blog/2017/02/20/multiple-independent-subdomains-in-a-wordpress-network/

    From the above article, you could try, and see whether the following code helps with allowing superadmin having access to the subsite dashboard:

    <?php
    add_action('muplugins_loaded',function(){
        if(defined('MULTISITE') && MULTISITE && !defined('COOKIE_DOMAIN') && DOMAIN_CURRENT_SITE !== $_SERVER['SERVER_NAME']){
            if(1 === preg_match('/^(?:www.)?((?:[A-Za-z0-9_\-]+\.){1,3}[A-Za-z0-9_\-]{2,})$/',$_SERVER['SERVER_NAME'],$aryMatches)){
                define('COOKIE_DOMAIN',$aryMatches[1]);
            }
        }
    });

    You can implement the above code as a mu-plugins, and see whether it helps. Please check this manual on how to use mu-plugins:
    https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.