Share users amongst two WordPress sites

If you have two WordPress sites and would like to share users among them, it’s quite easy. Both sites will unfortunately have to use the same database, with different table prefixes (Please note: This can cause issues with poorly written plugins that don’t use the WordPress prefix option).

On your first site, in the wp-config.php file, you’d set the table prefix like this:

$table_prefix = 'main_'; 

On your second site, in the wp-config.php file, you’d set the table prefix like this:

$table_prefix = 'other_'; 

Then, in your second site, you’d also add this line to the wp-config.php file, towards the top:


Your second site will now use the same users table as your first site. Some other people will recommend adding the line define(CUSTOM_USER_META_TABLE,'main_usermeta');, but this will cause issues with permissions and privileges.

I am currently working on a plugin that will allow you to share user meta such as roles between sites as well, without modifying the core WordPress code. The problem that currently exists is that user roles are stored with a meta key that looks like this:


And I’m having trouble finding a handy filter for changing this. Check back later for my solution (Probably as a plugin or a code snippet for your functions.php file.

3 Replies to “Share users amongst two WordPress sites”

  1. Actually, this may be a little more secure plus it explains getting through some other issues that may come up:

  2. Found this on a different form, worked for me!… I’ve pasted it below:

    Once you have the users sharing a database table as you described above, open your wp-config.php for both blogs.

    Copy the AUTH_KEY and SECURE_AUTH_KEY lines from your main blog’s wp-config.php to your second blog’s wp-config.php so that they are the same in both.

    Create a line in your main blog’s wp-config.php file that looks like this:

    define(‘SECRET_SALT’, ‘L3klg#a;&-,Ab;&UT+y’);
    You should replace the salt value string above with your own, possibly generated for you using this page. DO NOT simply copy and paste the above line, because that would be wrong-hearted.

    Once you’ve done that, copy the SECRET_SALT line from your main blog’s wp-config.php to your secondary blog’s wp-config.php file so that it is the same in both.

    Create the following lines in both wp-config.php files:

    define(‘ADMIN_COOKIE_PATH’, ‘/’);
    define(‘COOKIEPATH’, ‘/’);
    define(‘SITECOOKIEPATH’, ‘/’);
    define(‘COOKIEHASH’, md5(‘Another random string value!’));
    Important Notes:

    COOKIEHASH is normally defined in your wp-settings.php file on line 351. Unlike most of the other constants here, it doesn’t check if it’s already defined before defining it. On my server, this doesn’t cause any problems, but if you notice error messages like ‘COOKIEHASH is already defined’ or something, that’s probably the problem. If you want to hack up core files (which we’ve already done by now), you can comment out that line in wp-settings.php and that should take care of it.
    Remember to replace the COOKIEHASH value above with your own string.
    Save both wp-config.php files, clear your browser’s cookies and log in to either blog. Once your in the admin area, try hitting the admin area of the other blog and it should work fine.

  3. Hi Brandon;
    If this is an intrusion please accept my apology.

    I am having to use several themes to achieve the site I want to create.

    At this point there are 3 – the main root WP install and 2 other WP installs in separate folders (sub-directories I guess you would call them). What I need is to share the database in such a way that when a user logs in to any of the three themes (to say leave comments or ratings) they would be automatically logged in to any other of the other themes without having to log out of one and re-login to another . . .

    I have been searching for the answer to this for two weeks now. The answers I find either are not relative to my specific need or most of the answers are 1 – 5 years old & not specific to my current WP version – version of WP I have is the current 3.2.1 – plugins I have found thus far have not been updated to work with 3.2.1 – also, would sharing the same cookie be a factor.

    I am stuck from further development until I get this figured out – I have looked at the WP codex regarding setting up a network and multi-sites but I am on a shared server with godaddy and it is not recommended to use network/multisite on shared servers. I am new to wordpress so if you have or know of a source please treat me with instruction as if you were talking to a first grader 🙂

    Thank you so very much for your kind reply – you are greatly appreciated.
    Linda Lou

Leave a Reply