How to share users and logins across multiple WordPress installs?

Recently, I found myself in a situation where I needed to add a bbPress and BuddyPress “section” to a website (we’ll call this site B), although the main website (site A) and site B were supposed to have different WordPress installs. Lucky for me, both websites would be hosted on the same server so this made it the whole scenario easier.

After I finished it and got it working, I decided to write an article on it to prevent you from some of the headaches I got while doing this. Also the process could be extended to even more websites, in my case I was only going to need to synchronize login details and cookies between two WordPress installs.

Requirements/Scenario

  • Site A and Site B must be on the same top level domain (subfolders or subdomains)
  • Site A and Site B will be using the same Database

Probably obvious, but you will also need FTP access to both websites, we will be opening and editing wp-config.php for both websites. If you meet the requirements, we can move on.

(Optional) Do a full website Backup

Since we’ll be working with wp-config.php and the databases, it’s best to be safe and run a full website backup, or at least the database and wp-config.php

For this I recommend using Updraft Plus or WP Time Capsule, but just about any other solution will work. I recommend them because I’ve used them many times and never failed me.

Sharing Users and User Meta

In order to have the same login and password on both websites, we’ll be using the same database tables. If you’re using the default prefix, these should be called wp_users and wp_usermeta.

1. Check Site A’s table prefix

If you don’t know for sure your site’s table prefix, open Site A‘s wp-config.php and look for this line:

In most situations, it will be wp_, but if yours is different just remember it because we’ll be using it for Site B‘s wp-config.php too. Keep wp-config.php open, we’ll be needing more info later, as well as to edit it.

2. Installing WordPress for Site B

Keep in mind we’ll be using the same database as Site A, so you will have to use a different table prefix for Site B. In my example, I decided to use com_, short from Community. You can use whatever you see like, it doesn’t matter.
If you’re using tools for automated WordPress installation that do not allow you to select the database and prefix, don’t worry about it as you can chance them later from wp-config. Just make sure you have WordPress installed in a Subfolder or Subdomain.

Open Site B‘s wp-config.php, and replace database name, user and password to be the same as Site A.

Now both sites will be using the same Database. Make sure Site B uses a different table prefix.

3. Share WordPress Users between the websites

To do this,  all we need to do is to make sure Site B is using the same tables for users and usermeta as Site A. Open Site B‘s wp-config.php and add the following lines right before 
/* That’s all, stop editing! Happy blogging. */

Please note that wp_ is Site A‘s table prefix, if yours is different you need update these lines.

Great job, both sites are now sharing the same users (if you did everything right).

Sharing Login Cookies

Now that both websites are using the same login details, you will notice that if you switch websites you will have to login again. That can be fixed by sharing login cookies, here’s how to do it.

1. Edit Site A’s wp-config.php

Right before /* That’s all, stop editing! Happy blogging. */, add the following lines:

In the first line, you will have to replace yourwebsite.com with your actual domain. In the second line, you have to put your WordPress Site Address (URL), which you can get from Dashboard -> Settings -> General

Don’t close Site A‘s wp-config.php yet, we’ll still need some info for Site B.

2. Edit Site B’s wp-config.php

Similar to how we did for the database name, user and password, we will now copy the following lines from Site A and replace those existing in Site B:

Obviously you won’t actually find anything in there names stringof40characters, but some different random strings of 40 characters.
Next, we need to make sure Site B is sharing login cookies with Site A.

Similar to the previous step we will now edit Site B‘s wp-config.php and add the same lines we added for Site A.

Get Administrator rights on your Site B

After you’ve done the steps above, you will notice that your websites are indeed synchronizing login sessions, but you are not allowed to access the admin dashboard.
You will be greeted with this error message: Sorry, you are not allowed to access this page.

To gain access to it, we’ll need to manually edit wp_usermeta database table. There’s plenty of options to do this, most of you will have phpMyAdmin installed on your server.
Personally, I’m using Adminer (a.k.a. phpMinAdmin) because I rarely ever edit the database and I don’t need it permanently installed.
Next, open your Database and go to wp_usermeta table. If you’re using Adminer too, you’ll have to click Select data to find out wp_capabilities meta_key.

Copy the meta_value from wp_capabilities of your admin user, create a New item and set:

  • umeta_id (leave it blank, it will auto increment)
  • user_id: 1 (for most of you this will be user_id of the administrator on Site A)
  • meta_key: com_capabilities (com_ is the prefix for Site B. Replace it with your prefix)
  • meta_value: Copy-Paste the same meta_value from wp_capabilities for user_id = 1

When done, it should look like this.

And now you’re done, your websites are Sharing Users, Logins and you’ve given yourself Administrator role.

3 Comments

  1. Yash Choudhary June 7, 2017
    • Tazz June 7, 2017
    • MariusG June 7, 2017

Leave a Reply