I have missed a lot of time by searching answer to my question. For today I have two WP installations on the one server and one DB but with different prefix. I already shared users data and meta between two blogs and it working fine! But I still canât setup autologin or single sign on under two blogs. The code below does not work in WP3.8.
define('COOKIE_DOMAIN', '.domain.com'); //replace with the 1st website URL
define('COOKIEPATH', '/');
I’ll skip steps related to sharing DB and sharing users data and meta, based on assumption that you’ve done it correctly.
Let’s concentrate on wp-config.php of both sites. These are defines that MUST BE IDENTICAL for both sites:
and
generated once only, KEYs and SALTs, copied to wp-config.php of both sites.
Now, if you login as any user on one site, you will be logged in, as the same user on the second site.
But wait. What happens, when you create a new user on one site, login as just created user on the same site, and try to access /wp-admin/ of the second site? You can expect to see the following message:
This is because, on the second site, the newly created user does not have any role assigned, yet.
How to avoid user not being synchronized on both sites, in case of user’s creation or change to user’s profile?
I wrote a plugin, which should be placed in /wp-content/mu-plugins of both sites. Let’s make a new file
fpw-sync-users.php
, with the following code in it:and copy it to both destinations.
Now, edit the plugin of the first site, by replacing ‘wp_’ with real table prefix of the second site, in all three
$other_prefixes
arrays. Edit second site’s plugin, using real table prefix of the first site, as a replacement.From now on, users on both sites will be fully synchronized, and login on one site will make this user, logged in on both sites.