Wordpress - Whats the best way to share user data across multiple Wordpress websites?

Ok, first of all, I feel like an idiot, although in my defense most of the articles that talk about this don't mention a very crucial detail in making this work. The answer is that you need to set permission for at least one admin in the database. This info can be found in the Codex here: http://codex.wordpress.org/Editing_wp-config.php#Custom_User_and_Usermeta_Tables

After you set up the wp-config.php file, it's imperative that you make a change to the master usermeta table (in my case wp_usermeta) field wp_capabilities row, and meta_value column. Do this via phpMyAdmin.

Note: Do this for at least one user admin to log in. You can adjust all other users/admin roles from the backend once you get in.

Screenshot of what users permissions will be changed

For each website that is created, it needs to have that new sites prefix assigned the admin user role.

In my case since I've only got this working on 2 sites at the moment it looks like this:

a:1:{s:13:"administrator";s:1:"1";}
tbs_capabilities = a:1:{s:13:"administrator";s:1:"1";}

Screenshot of wp_usermeta value

The first line sets permissions for the default table prefix (in this case wp_), and the second line sets the permissions for the second website (in this case with the tbs_ prefix).

Thanks to brasofilo for the comment that pointed me to dig a little further to finally solve my issue!

I hope that this answer can help other who were having the same issue I was.


When sharing wp_users and wp_meta there is another problem, other wordpress installation does recognize the users but it does not recognize the roles of users coming from the other website. The role shows up as undefined.

So, you edited your wp-config.php as required:

define('CUSTOM_USER_TABLE', 'someprefix_users');
define('CUSTOM_USER_META_TABLE', 'someprefix_usermeta');

I think the easiest way to do this, without tinkering with the db, is by using wp internals. Upon login, it is possible to assign a role. Let's say, we need the contributor role for everyone, and administrator role for the user 'superman'.

function check_user_role($user_login, $user) {
  if ( $user_login == 'superman' ) {
     $user->add_role('administrator');
     } else {
     $user->add_role('contributor');
  }
}

// the action fired on login
add_action('wp_login', 'check_user_role', 10, 2);

So, users coming from the initial website get the 'contributor' role assigned when they login.

  • You may delete the user check after you got logged-in with the admin user.
  • Users may have more than one role, capabilities matter.

http://codex.wordpress.org/Class_Reference/WP_User