One of the things I’ve always wanted to know how to do was create two separate WordPress installations but have the same users.
This turned out to be a lot easier than I thought it’d be all thanks to a WP support forum post on sharing user tables.
I’m actually using this at Theme Hybrid for some future parts of the site. So, this thing is being tested live.
How to share the same user tables
Note: I’ve tested this on WordPress 2.5, 2.6, and 2.7 (latest from trunk).
First, both installations of WordPress should probably be the same version.
Both installations should be within the same database (I’m not sure how/if this would work on separate databases).
I also recommend backing up your databases anytime you change code that might mess with it, but it shouldn’t be necessary.
Let’s suppose you have Blog A and Blog B. Blog A has been your main installation for a while, but you want to add a second installation with the same users (Blog B).
Let’s also suppose you’re using the default WordPress table prefix wp_ for Blog A.
Blog B’s table prefix should be different. We’ll change it to something like this in Blog B’s wp-config.php file:
$table_prefix = 'blogb_';
In the same file, find this line:
/* That's all, stop editing! Happy blogging. */
Just above it, add:
define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USER_META_TABLE', 'wp_usermeta');
This tells Blog B’s installation that you want to use the user and usermeta tables from Blog A’s installation. However, the rest of Blog B’s content will come from its own unique tables.
Suggestions or comments
I don’t generally work a lot with databases, and I assume this is pretty easy for more advanced users. If there are easier ways to handle this, then I’d love to hear what you have in mind.
Otherwise, have fun with your two installations.
great justin this was what i was searching for and u delivered it straight to my mail.
thanks justin for sharing.
Of course this is the easiest way to share tables, not only the users table but even if you run multi-lingual blog which are installed under different directories.
Besides this is similar of how several web sites like Yahoo and MSN manage sessions across multiple domain names. For example if I logon Yahoo.com I can still remain logged in on flickr.com
I assume if both domain names are on the same account or the database host is not “localhost”, sharing WP DB tables across domain names is easy, too.
Thanks for sharing.
krishna
No problem. I figured I’d share it because it’s very useful and helped me out.
J Mehmett
I had never thought about running a multilingual blog with it before. That would be a great use of it.
I would assume that we can share any tables we choose too, not just the user tables.
Nice! Like what you said…and I like your name.
My husband, “Justin” and I leave on September 30th to backpack to various countries around the world for a year or so. As we have been planning for our adventure we have been updating a blog. http://www.nomadbackpackers.com
Justin and I both publish stories, etc. It seems like you’ve got a lot of experience with wordpress.
Departure: in 8 days!!! We would love to have other opinions, ideas, encouragement, advice, helpful tips, and more left as comments.
Thanks,
Natalie
Thats what I’m planning now. I’m going to build a website for a local TV and radio here. They wanted to run a multi-lingual site, and a separate sub-domain for the TV.
So, I can make the site share several tables across all the installations. I’d go to WPMU, but I know, I don’t need that since what I need is only sharing tables.
I assume two bbPress installation can share database resources, too, because, WP and bbPress can share the users and usermeta tables.
That sounds cool. Definitely let me know when you have the site up. I’d like to see how everything’s integrated.
I’m guessing the bbPress installations would be the same also.
As you probably know, I have my main support forums and the ideas forum running on two separate installations. What I done for integration there was just integrate both installations with the main WordPress install, so all the user tables are shared.
Actually, the showcase blog is integrated also. I just haven’t added a login form to it yet because of some cookie issues running different versions of WordPress and bbPress 0.9. Once bbPress 1.0 is officially released, I’ll work all that out.
That is interesting, I was really wondering about all the framework you have done to make ThemeHybrid running under several installations.
Justin,
I didn’t think that we could do something like this. sharing two tables user tables between two wp blogs.
Thanks for the tip…
So, could this be expanded to 4, 6, 20 installations?
Thanks Justin.
Nihar
No problem. It was an issue I needed solved, so when I found the answer, I figured I ought to share it.
WordSkill
I haven’t tested it on more than two installations, but I see no reason why it wouldn’t be the same for more. Just make sure all user tables are defined as the original (Blog A in the post). So, the third, fourth, or twentieth installation should use the same user tables as the original.
Justin have you tested other users besides the admin account using your code? if you did you probably noticed that you don’t have permissions regarding those newly created account if not kudos for you!.
anyway have you figured out how to share user cookies across blogs so if you logon to one, you can be logged on the other?
Hi! I’m new here!…
Anyway, I wanted to have 3 blogs with the same users and I did follow your instructions. But when I created a new user to my main blog and I tried to log into any of the two others, I did logged into but I wasn’t able to reach the Dashboard. It justs shows the error: “You do not have sufficient permissions to access this page.”.
What is wrong?… Any ideas??…
jc min
Yes, I’ve tested several different user roles and accounts. To share cookies, you probably need to have all three of the same versions of WP and with the same cookie settings.
#FN$#
You’re probably best off heading over to the WordPress support forums. They’ll be able to help you much more than I can.
Thanx for the help anyway. I read a lot of posts and I can’t figure this out… I may disable user registration…
I have an important question: imagine that you have Blog A, and you create a Blog B. So, what you do is call the user database from Blog A when you’re installing Blog B. For now, all good!
But is the information synchronized? For example, if a user registers on Blog B, will he be able to login in Blog A? Or else, do all the users need to register at Blog A in order to use the same login throught the network?
Do you see what I mean? Well, even if it’s not synchronized, I guess that the solution will be to redirect the user always to the Blog A’s registration page, right?
Thanks very much for the excellent post, simple and precise!
Greetings,
Rui Zamith
Rui Zamith
Yes. The entire point of this is that they’re synchronized.
Well, even if it wasn’t synchronized, it would still be extremely useful - at least, we could find a solution for it!
In that case, it’s definitely an amazing and perfect solution for people like me that use several WP installations as single global website. You can even use bbpress has your forum tool, synchronize it with Blog A’s database, and totally centralizing your user info. Impressive!
Thanks.
Hi - I relaise this is probably a dumb question but I am planning on getting a web-site and I was wanting to run two wordpress blogs on it. Am I able to run two completely separate blogs by installing them separately?? The host I have has multiple MySql databases so if I create two and then install wordpress into two subdomains am I able to simply have two blogs?? Or do I need to do something like what you’ve done?? It seems very complex. I am a really really non-intelligent first time user and I really want to figure this out.
Thanks for listening.
Best,
Dick Whyte
Rui
If it wasn’t synchronized, it wouldn’t be useful at all. It would be useless. That’s the entire point of this post. I could’ve titled it Synchronizing the users of two WordPress installs.
If we weren’t synchronizing them, what would we be doing? That’s like saying, “Add these two lines of code to achieve nothing.”
Dick
Yes, you can run two separate blogs. If you want to integrate the users, then you need to use the same database. If not using the same database, then you’ll have to come up with a more complex solution than these simple two lines of code.