We have 2 WordPress sites in 2 different sub-domains like test1.abc.com and test2.abc.com . Both sites have wp-require plugin activated and only logged-in users can see the site. We want to make a system where if a user logged into one site, he should be auto-login into the other one.
What I did:
After some searching I know I need to use one database for both sites. So I have done these steps:
- I have download the whole database of test2.abc.com site and change all prefix
wpmo_, replace it in whole database and upload it into first site's database.
I added these 2 lines in
wp-config.phpof the second site, to define that second site should use first site's user table not its own one.
define('CUSTOM_USERMETA_TABLE', 'wp_usermeta'); define('CUSTOM_USER_TABLE', 'wp_users');
Now, the second site is using the first site's users and I am able to login to the second site by the user details of first site.
The next problem is cookies, so I added these lines in
wp-configof both sites.
define('COOKIE_DOMAIN', '.abc.com'); define('COOKIEPATH', '/');
Now I logged in into test1.abc.com and when I go to test2.abc.com , it asks me to login. That means cookies are not passing from the first site to the second one.
Both subdomains are on same server and sharing same database user table.
I know it is a cookie issue and I have gone through many articles on that, but they all talk about sharing cookies between a domain and its subdomains. Here I am having 2 subdomains.