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

admin2025-06-05  3

First of all, Multisite isn't what I'm looking for. I have 5 websites using Wordpress all on separate domains that I would like to enable user accounts for. I need user data to be shared across the entire network and when a user creates an account, they would have instant access to all other websites as well. What I'm trying to do isn't recommended by Wordpress when using Multisite:

If you plan on creating sites that are strongly interconnected, that share data, or share users, then a multisite network might not be the best solution. - (1st paragraph, 3rd sentence)

I've tried using the "shared user table trick" as mentioned here and here / and a number of other places...the problem is that this information is 2-7 years old and I'm using Wordpress 3.5.1 and this "trick" doesn't seem to work.

I've attempted to insert this code into wp-config around the $table_prefix line.

define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USER_META_TABLE', 'wp_usermeta');

Long story short, I don't think this trick works any more as I am unable to log in to the second site on the admin side at all.

Any suggestions on what the best way to link this data would be?

First of all, Multisite isn't what I'm looking for. I have 5 websites using Wordpress all on separate domains that I would like to enable user accounts for. I need user data to be shared across the entire network and when a user creates an account, they would have instant access to all other websites as well. What I'm trying to do isn't recommended by Wordpress when using Multisite:

If you plan on creating sites that are strongly interconnected, that share data, or share users, then a multisite network might not be the best solution. -http://codex.wordpress/Before_You_Create_A_Network (1st paragraph, 3rd sentence)

I've tried using the "shared user table trick" as mentioned here http://wordpress/support/topic/multiple-sites-same-users-how and here http://xentek/articles/528/implementing-the-wordpress-shared-users-table-trick/ and a number of other places...the problem is that this information is 2-7 years old and I'm using Wordpress 3.5.1 and this "trick" doesn't seem to work.

I've attempted to insert this code into wp-config around the $table_prefix line.

define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USER_META_TABLE', 'wp_usermeta');

Long story short, I don't think this trick works any more as I am unable to log in to the second site on the admin side at all.

Any suggestions on what the best way to link this data would be?

Share Improve this question asked Feb 11, 2013 at 23:36 IanIan 9891 gold badge7 silver badges16 bronze badges 5
  • 1 I don't get why CUSTOM_USER_TABLE wouldn't work... See if there's something here: wordpress.stackexchange/search?q=CUSTOM_USER_TABLE – brasofilo Commented Feb 12, 2013 at 0:13
  • When I use CUSTOM_USER_TABLE users do get shared between website, however, on the second website, I cannot log in as an admin whatsoever. Searching around for hours and finding plugins and articles that are 2-7 years old lead me to believe that this trick no longer works in 3.5.1... – Ian Commented Feb 12, 2013 at 6:40
  • The question is that this is not a trick, it's a core feature. Seems that no bug has been reported, and nothing relevant shows up in [wp-hackers] list... – brasofilo Commented Feb 12, 2013 at 6:50
  • Thanks for your comments. I was able to find the answer by taking a deeper look into some things that I saw in your links. I've posted my solution below. Thanks again @brasofilo – Ian Commented Feb 12, 2013 at 7:24
  • Really great you almost covered all the ways on how to share the users. but ive a little different situation here. Ive 5 wordpress website that each particular website has its own db. How can i use your solution to connect all separate user tables in a way when a new user registers on any of 5 websites, he could immediately login to any of other websites using a single registration ? Im aware of some way to accomplish this in a single database using the WPMU but im not really finding any way to do it on seperate installations of wordpress. Will appriciate any help. Thank you – user47152 Commented Feb 4, 2014 at 19:32
Add a comment  | 

3 Answers 3

Reset to default 8

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/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.

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";}

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/Class_Reference/WP_User

I had to create a new row:

meta_key='tbs_capabilities' meta_value='a:1:{s:13:"administrator";b:1;}'

and user_id=1. The method you described didn't work.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749115382a316492.html

最新回复(0)