74 responses to “Installing two WordPress blogs with the same users”

  1. krishna

    great justin this was what i was searching for and u delivered it straight to my mail.

    thanks justin for sharing.

  2. J Mehmett

    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 :D

    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.

  3. Natalie

    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

  4. J Mehmett

    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.

  5. J Mehmett

    That is interesting, I was really wondering about all the framework you have done to make ThemeHybrid running under several installations.

  6. Nihar

    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…

  7. WordSkill

    So, could this be expanded to 4, 6, 20 installations?

    Thanks Justin.

  8. jc min

    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?

  9. #FN$#

    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??…

  10. #FN$#

    Thanx for the help anyway. I read a lot of posts and I can’t figure this out… I may disable user registration…

  11. Rui Zamith

    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

  12. Rui Zamith

    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.

  13. Dick Whyte

    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

  14. Cliff

    Hi, Justin…

    Good stuff… I’m looking forward to trying this out this evening, as it’s been a goal of mine for a while now.

    I think that the commenters who ask about synchronization are concerned that their users would have to register at a ‘master’ site – Site A – in order to be universally registered with Site B, Site C, Site D, and so on. To RuiZamith’s point, that would still be better than having to register at each site individually, but not as nice as the reality you’ve enabled here, where I can register at Site C or Site D and still be registered for all of them.

    Synchronization implies an adjustment of two or more tables to match each other, so we should stop using that term here altogether. To abate the confusion that RZ and others might be experiencing, we should call your strategy ‘table sharing’, where there is only one users table shared by Site A, B, C, etc. , and let’s call the strategy RZ wonders about ‘table updating’, where the records from wp_users_A are regularly copied into wp_users_B, wp_users_C, etc. ‘Table updating’, if it were the only way to solve this problem, wouldn’t be completely ‘useless’, but let’s be glad that WP is better designed than that.

    Thanks again for a great solution to the problem, Justin! Bravo!

  15. Davor

    set the COOKIEPATH to the root:

    in wp-config.php

    add this

    define(‘COOKIEPATH’, ‘/’);

  16. Davor
  17. Davor

    Have anybody try this plugin http://wp-hive.com/download/, i can not set it up

  18. Brett

    I tried installing this with WP2.7 as per your instructions, but as soon as I add the lines:

    define(‘CUSTOM_USER_TABLE’, ‘wp_users’);
    define(‘CUSTOM_USER_META_TABLE’, ‘wp_usermeta’);

    I can no longer log into the second wordpress installation using admin. This (obviously?) is because that user “admin” was overwritten by the other admin. What I don’t get is why the other (original) admin has permissions to work within the new blog installation.

    Do you have any ideas?

    Thanks!
    Brett

  19. Brett

    I found the solution on wordpress’ support site. This solution also keeps you logged in across sites. Scroll down to “Wolthers” comment.

    http://wordpress.org/support/topic/164758?replies=13

    Thanks for getting me started on the right track here :)

  20. Brett

    Although it’s probably not worth going back on a functioning existing site, people may also be interested in wordpress MU (multi user install):

    http://mu.wordpress.org/

  21. schikowski

    Thank you for sharing this idea, Justin. It seems like a great workaround if someone doesn’t want to use WP MU.

    Cheers, schikowski

  22. Borko

    Does anyone know how to share the cookies so you stay logged in?

  23. Patrick DeVivo

    Hey Justin,
    This post was really useful for me, but do you know if by any chance it works when syncing the users in a standalone WP install with those of a WPMU install? I want members on my current WP install to be able to use their same account with a WPMU install. I’m trying to build a network using WP, WPMU, and bbPress. So far syncing WP and bbPress was pretty easy, but I’m unsure about WP and WPMU.

    Thanks,
    Patrick

  24. Kate Mag

    Wow, i never knew that was possible. Cool! Thank you, Justin

  25. Didik

    Hi, Justin. I must say this post helps me a lot! But now I’m facing some problems:

    Let say Blog A and Blog B, whereas Blog B is using user data from Blog A. Blog A and B sharing a database (just like you suggested in this post, using custom prefix to define each one of them). Now what I would ask is:

    1. If user registering to Blog B, where will be the registered member database? Is it in A’s or in B’s?
    2. I wanted to write a post in Blog B but somehow can’t assign the author of my choice, meaning the author combo-box isn’t show up. What could be wrong?

    Thank you,
    Didik.

  26. Ajay M

    I want to share the same user table with 4 wordpress blog.
    Any idea about how to proceed?
    I would like to reiterate that I have the old one with good user base present now and the other 3 are brand new and already installed.

    If u can throw some light I will be glad.

  27. Ajay M

    Forgot to say that all my Wordpress are installed on completely different database…but they have save prefix wp_

  28. Ajay M

    Thanks a lot Justin.

    Could you at least let me know if there will be any issues if I will operate 4 installation of Wp from same database? Like while taking back up and restoring them?

  29. Ajay M

    Hurray…I did it…
    I took one of my existing Db and exported it and then renamed the prefix from prefix old to prefix new and then imported that to the existing primary DB for the old blog and now all seems fine.

    Thanks again for the help.

  30. Borko

    No luck…. with adding this to my wp-config.php file

  31. Jeremiah Lewis

    Great article! This actually helped me determine what I needed to do for a site I’m working on.

    How does one install 2 different instances of WP on one site? Is this a matter of installing the second WP to a subdomain/subdirectory?

  32. Ajay M

    All seems fine except users has to log n individually in each blogs. Any workaround for that?

  33. Sumit

    thanks for this article.

    BUt i found a lot of crazy things in the comments here. There is NO SYNCHRONISATION between anything! The installations share THE SAME DATABASE! So if you register in blog a or blog b it will be written in the database that the Blogs share! And that causes you can log in in both blogs. There is just nothing to synchro… Thats the good point ;-)

  34. study

    I don´t speak english but I understand code. You are my hero. thanks

  35. jo

    thanks a million
    after searching for a few hours, your two lines saved my day :)

  36. Nigel

    Thank you very much, those two lines did exactly what I needed.

  37. Dave

    Thanks i was looking for that, i have read a lot a blogs vut they where so freeaking techical, but this was easy to follow for a code n00b like me :)

    Thanks mate.

    Dave

  38. ZoltakSmash! News » Small Victories

    [...] Justin Tadlock posted about sharing users between “blogs.” One of the things I’ve always wanted to know how to do was create two separate WordPress installations but have the same users. [...]

  39. ilan sitesi

    thank you for very useful tips and good idea. that’s what i need in my classified site. i will use this tip. thanks.

    Unnecessary link removed by the administrator. There is an input field for a link to your site.

  40. Sumit

    oh i got a question about this:

    are the user permissions written in the user_table too ?
    Because i want different permissions for the users in the different blogs. Is that possible or do they automatically have the same permissions?

  41. Drey

    Same issue as Sumit here! I’m using your technique for sharing user tables, but it seems to mess up if using different Roles in the different blogs… any idea how to solve? I’m using Role Manager plugin, and when I try to call the list of the profiles of custom roles, it throws “Warning: array_keys() [function.array-keys]: The first argument should be an array in… on line…” (on that line of the template file it has a ” $user->role = array_keys($user->$role); // assign ‘role’ property to $user”… i know it might be a long shot to ask for help here but… any idea on how to solve it?
    Thanks in advance!

  42. Kim

    Thanks for the tutorial Justin. I’m working with setting up 2 WordPress blogs now (both 2.7.1), one in the root and one in a subdirectory, and wanted to share the same users across both.

    I’ve followed your instructions, and some pointers from the comments, including the suggestions in Wolther’s post in this thread from the wordpress.org forum: http://wordpress.org/support/topic/164758?replies=13

    With only including the defines for the user and usermeta tables and the cookies in the 2nd install’s config file, I am unable to login to the second blog. I had to include the following (define(‘CUSTOM_CAPABILITIES_PREFIX’, ‘wp_’);) in the config file and make the change to wp-includes/capabilities.php to be able to log into the second blog.

    Like others, I don’t like having to modify a core file to get something working. Is there any way to create a plugin using the changed code for wp-includes/capabilities.php so that it will override the existing core code? It doesn’t look like the devs want to commit it to the core, from what I read in a couple of Trac tickets.

    Thanks in advance for any help you can provide. :)

  43. Kim

    Thanks Justin, I appreciate it. :)

  44. prince

    Hi there,

    I am registering a User with an “Editor” role in Blog A, and when I look at Blog B, the Role is set to “None” instead of “Editor”.

    I’m using memberwing plugin too… When I register a user on a “Certain Role Level” on blog A, it appears as Role: “None” to blog B.
    (and vice versa)

    Please help.
    Thanks

  45. jan

    You gotta be kidding me! And two and a half years later, here I am at a two lines solution, having designed 2 plugins to do the same. I thought I was smarter than this. You my man…

  46. Stephen R

    Anyone using this technique might also be interested in the wp-orphanage plugin: http://xentek.net/code/wordpress/plugins/wp-orphanage/

    What this does is — any time WP encounters a user without any privileges, it automatically makes them a subscriber.

  47. Elizabeth K. Barone

    I wish I’d found this a while ago! Are the user roles the same in both blogs? What if you want someone to be an Author for one blog and a Subscriber for the other?

    1. David Riveroll

      I really don’t know if this will work, cause I’m kinda a beginner in WP. But I’d try to share only
      define(‘CUSTOM_USER_TABLE’, ‘wp_users’);

      and not
      define(‘CUSTOM_USER_META_TABLE’, ‘wp_usermeta’);

      because this is were the capabilities are set, but as I said, I don’t know if that would mess with something and I haven’t tried it yet.

  48. David

    Elizabeth, I think they’d need to be the same role, because it’s just one database table that stores the info for both blogs….

    @topic. I really wish one day the Wordpress people could figure out a way of allowing for this kind of thing by default, without having to screw around with files, etc..

  49. jcwynford

    hi! Just wondered if you also tried sharing user table between a main wordpress and a wordpress MU? I need some help for this, thanks!

  50. EMG

    Hey there Justin!

    I wish I had come across this post of yours when I had been reading up on your sidebars discussion and user control over themes discussion!

    I thought I would give you an update on this method of sharing user tables and let you know that I followed your instructions for sharing a user table between two WP installs, both version 2.8.2 (within the same database, made sure all the prefixes were done correctly, and added the appropriate lines in my configuration file) and I received a permissions error.

    I went to the WP thread you linked to and read up on the discussion and found that other users had similar permissions errors and so I additionally altered the core capabilities file as well as per instructions.

    Maybe it’s just 2.8.X or something, but I am still getting permissions errors.

    It does seem like the user tables ARE shared as I only get errors associated with the logins associated with my main account and it seems like everything ELSE about the install is fine. I just can’t get rid of my permissions errors.

    Creating a new account post user-table linking on my primary account and trying to log into my secondary WP install also brings up the error.

    I’m not sure if you’ve run into any such errors yourself or if anyone else has tried it for 2.8, but these are the errors I’m running into myself and so I figured I’d share.

    Thanks for all of your posts; the content and resulting discussions are awesome!

  51. Laura

    I thought this couldn’t be done. Thank you (again!) for your insight into this.

  52. Ah John

    Thanks Justin for the excellent tutorial!

    I have a question about the SEO for 2 blogs within 1 domain.

    I’ve installed 2 separate WordPress copies for the English version and the Chinese version, under /ahjohn_en and /ahjohn_cn directories respectively. When the user reaches http://www.ahjohn.ca, the top index.php redirects them to either http://www.ahjohn.ca/ahjohn_en or http://www.ahjohn.ca/ahjohn_cn according to their last choice stored in the “cookie”. I also have 2 separate sitemap.xml files under ahjohn_en and ahjohn_cn, but have no top sitemap.xml under for the entire website.

    My question is: how can I let the search engines know or find all of the contents and traffics from each blog as a “whole” report for the entire website “ahjohn.ca”?

    Am I on the right track? What should I do to reach my goal?

    Please help me out. I really appreciate it!

  53. Ah John

    (sorry, the < and > were NOT displayed in the previous comment. re-submitting it)

    Thanks Justin for the excellent tutorial!

    I have a question about the SEO for 2 blogs within 1 domain.

    I’ve installed 2 separate WordPress copies for the English version and the Chinese version, under <hosting-root>/ahjohn_en and <hosting-root>/ahjohn_cn directories respectively. When the user reaches http://www.ahjohn.ca, the top index.php redirects them to either http://www.ahjohn.ca/ahjohn_en or http://www.ahjohn.ca/ahjohn_cn according to their last choice stored in the “cookie”. I also have 2 separate sitemap.xml files under ahjohn_en and ahjohn_cn, but have no top sitemap.xml under <hosting-root> for the entire website.

    My question is: how can I let the search engines know or find all of the contents and traffics from each blog as a “whole” report for the entire website “ahjohn.ca”?

    Am I on the right track? What should I do to reach my goal?

    Please help me out. I really appreciate it!

  54. Jesper

    Well, i have used this for a while now but i have always had the same problem, when a user register at blog A, he get the appropriate roles, but on blog B he´s roll is set to None and i manually have to set user roles!

    Any solution to this without using any plugins?

  55. brandon

    how do i add a second blog to an existing blog and database?
    i wanted my main blog for my website news, a second for a current project im doing, and a third for my girlfriend and i to record the times with our dog.

    is there a benefit to having the same user name and info from one blog for all of them?
    or cant i just install 3 wordpress databases/blogs and make all the logins the same for all the 3?

  56. Ed

    Everything was working perfectly until I upgraded my blogs to WP version 2.8.4 recently. Is anyone out there experiencing similar issue? Better yet, does anyone know how to resolve the issue? I checked the wp-config.php on all of my blogs and they were left intact during the upgrade….

  57. Sharing users across multiple WordPress installations | Frank P. Walentynowicz

    [...] reading Justin Tadlock’s article “Installing two WordPress blogs with the same users” I have decided to implement this method in two of my test installations. Well… it did [...]

  58. samson

    i have 2 wp blogs (main and sub domain) so, i want them to share a wedgets is there any one helping me…?

  59. Frank P. Walentynowicz

    Ed – I think you forgot to reapply changes to capabilities.php file after the upgrade.

  60. Raize

    Worked perfectly with 2.9

    thanks

  61. Brooks

    I am using 2.8.6 and am having a similar permissions problem when logging into my secondary blog.

    These are the pieces of code I have added:

    in wp-config.php:

    define('CUSTOM_CAPABILITIES_PREFIX', 'wp_');

    in wp-includes/capabilities.php:
    replaced:

    $this->cap_key = $wpdb->prefix . 'capabilities';

    with:

    if (defined ('CUSTOM_CAPABILITIES_PREFIX')) {
    	$this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities';
    	}
    	else {	$this->cap_key = $wpdb->prefix . 'capabilities';
    	}

    Does anyone know if this code still works with 2.8.6 or is there another fix? Basically, if I can’t get this to work, I am locked out of my admin for my secondary blog.

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (e.g., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.