Using a Custom User Table Share Users Between Two WordPress Installs

April 28, 2009   ·   By   ·   4 Comments   ·   Posted in Admin, Customization, Wordpress

In one of many, many strokes of genius, the WordPress core developers threw in a bit of code to allow users (ok, other developers) to define a custom user table, and a custom usermeta table for a WordPress install.

In it’s simplest form, you can point your WordPress user table at that of another blog on your server. Doing so means both blogs (and why stop at 2?) share user information: passwords, usernames, author bios, etc etc. If you’ve got a site that requires numerous different, separate WordPress installs (think something along the lines of, but the same authors often write on many or all of them, this is a great, and easy solution.

Enough Already, Give Me the Code

Yes Sir.  Just slap this code in your wp-config file:

define('CUSTOM_USER_META_TABLE', 'new_usermeta_table');

It’s pretty self explanatory from there – just define a custom user table, and a custom usermeta table, and you’re good to go.  Want your users to share login info across different blogs, but be able to have a different bio for each one?  Define a custom user table, but leave the default user_meta table.  Everything stored in the users table (ID, login, password, nicename, email, url, and display name, among other things) will stay the same across all blogs.  Everything else (nickname, user level, First Name, Last Name, and many other things), will be blog specific.

  1. nirok

    i already have a blog with 500 users and want to create a new wordpress install for another area on the website. Will this allow me to allow those users to integrate with the new wordpress install without having to login again? or atleast login with the same user info? i’m also confused which wp-config file do you add thsi to?

  2. @nirok both of them should be safe if your not sure and you know the correct value.

    Sadly there is more to it than this. To login on one site and be logged in on the other, you need to sort out cookies.

    And then to top it off, you need to modify the core file capabilities.php so that it uses the correct user roles table, else youll get permission errors trying to login to the admin panel of the second blog.

  3. how can i share more then two wordpress site with same user table ? and how can we define more tales in below functions

    define(‘CUSTOM_USER_META_TABLE’, ‘new_usermeta_table’);

    can we write like define(‘CUSTOM_USER_TABLE’,'new_user_table’,new_user_table2); ?

    • You should be able to have more than 2 sites share a users table – just point them all at the same table.

      As for having a site use more than one table – That’s not possible, without significant extra work. WordPress wouldnt be able to just merge those tables on the fly to get good data – so if you want to merge tables like that, you’d need to do so with an external script (which could be really hard, or even impossible).

Submit a Comment