Webprogramo > Blog > Wordpress > A single users table for multiple WordPress instances

A single users table for multiple WordPress instances

It is possible, it is easy, but...

Alejandro Lopez

2 agosto, 2017

Webprogramo > Blog > Wordpress > A single users table for multiple WordPress instances
SHARE! and the author will get a Yummy Cookie :
Share this...
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter

To explain how to use a single users table for multiple WordPress instances let’s start assuming that you already have a WordPress site named «My Travels» and you need to create another one on your server to talk about «My Jobs» (yes, so weird example, but it works haha). Now, you love your users and you can’t afford to lose them, so you want to use the existing users database in your new «My Jobs» site.

The good news is that you can use a single users table for multiple WordPress instances, and it is easy! How?

First, you need to focus on concentrating your seven chakras on downloading WordPress, modifying the wp-config.phpfile to set the MySQL database name, user, and password for database connection, set the «Authentication Unique Keys and Salts» (always set them please) and set a tables prefix ($table_prefix).

The tables prefix.

The table prefix must be different from your existing WordPress. Why? Because we need to use the same database of your existing WordPress installation, so, your new WordPress has to create its own tables, and they need to be unique.  For example, let’s think your main WordPress use «travels_» as table prefix, then, it uses «travels_posts» to store your trips information, and your new WordPress will need to create a post table too, so, to evade collision and a possible damage, it is mandatory to create a unique and different prefix for your new WordPress e.g., «jobs_» prefix will create «jobs_posts» table.

After you have set up your wp-config.php file and before start installing your new WordPress, you have to put these two constants on it.


// "travels_" is your already installed WordPress tables prefix.
define( 'CUSTOM_USER_TABLE', 'travels_users' );
define( 'CUSTOM_USER_META_TABLE', 'travels_usermeta' );

Now you can run your WordPress and follow the famous «5 minutes installation», your new WordPress will use the existing main_users table and main_usermeta.

It is important to know that if you want to use only the primary user information and not the metadata you will need to set CUSTOM_USER_TABLEconstant only and not theCUSTOM_USER_META_TABLE.

Important Notice (The bad news =/):

For security reasons, WordPress sets «users capabilities» for each different instance installed on your server. It means that only your Administrator or Super Administrator will have full access to your sites, so, you will need to assign roles to your users on your new «My Jobs» site. These users without role are called «Orphaned Users».

There are a couple of plugins that will help you with the Orphaned Users, like WP-Orphanage Extended» or «User Role Editor» for Multiple user role assignments.