Login once to access multiple WordPress installations

Featured Image

My previous article Sharing users across multiple WordPress installations explains how to prepare for our current task. In order to be able to access multiple WordPress blogs with only one login we have to have common users across those installations. This article will deal with additional requirements necessary to accomplish our goal.

WordPress authentication is cookie based which means that after successfull login the cookies identifying logged in user are created. Normally these cookies are different for different installations. How to make them identical for all shared installations will be explained later within this article. If you look into wp-config.php you'll find four defines for security keys:

  • AUTH_KEY
  • SECURE_AUTH_KEY
  • LOGGED_IN_KEY
  • NONCE_KEY

Above keys are being called Authentication Unique Keys.

Important: they have to be identical for all of our shared blogs.

There is one more key and two salts used in the process of authentication:

  • SECRET_KEY
  • AUTH_SALT
  • LOGGED_IN_SALT

Values for these key are being generated internally by WordPress unless you define them in wp-config.php.

Important: these values should be exactly the same for all our shared blogs.

Salts are MD5 values and you can generate them here.

Now it's time to make our cookies work. All our shared blogs should reside within the same domain (either in subdomains or subdirectories). For this we will need eight additional defines in our wp-config.php:

  • COOKIE_DOMAIN
  • COOKIEPATH
  • USER_COOKIE
  • PASS_COOKIE
  • AUTH_COOKIE
  • SECURE_AUTH_COOKIE
  • LOGGED_IN_COOKIE
  • TEST_COOKIE

First two defines should be:

define('COOKIE_DOMAIN', '.yourdomain.com');
define('COOKIEPATH', '/');

Please note the dot '.' in front of domain name. It is necessary for the cookies being accessible across all subdomains.

Next six values are names of the cookies being part of the process. I have generated these names using GRC "Perfect Passwords" Generator. There is another one - Secure Password Generator, suggested by Jacke H, one of our visitors.

Below - wp-config.php for one of our shared installations:

<?php
/**
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, WordPress Language, and ABSPATH. You can find more information by
 * visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
 * wp-config.php} Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don't have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'abc');

/** MySQL database username */
define('DB_USER', 'abc_admin');

/** MySQL database password */
define('DB_PASSWORD', 'password');

/** MySQL hostname */
define('DB_HOST', 'hostname');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/**#@+
 * Authentication Unique Keys.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY', 'LjeTKG`U=gD$-2>{2|utk-RZ0~V]}/aDf>-2(}{a5pN7Tp)D0(*~*_jB[9:)%5ON');
define('SECURE_AUTH_KEY', '-%F+bE+?qSCE1[z1Rxi:~OC+C =6-l-+H)G:23kO-1[ppj<^ZrW}k!?E|nzOssG!');
define('LOGGED_IN_KEY', '@(-r&4U%gpwZoRvtW~G t9yIx0/0;x1o>eep^D~vsW}T@O=,W*4DbNodM{g@eQ[}');
define('NONCE_KEY', '0M%7po9BecM#u:[clr(-lmWvhM$I7MFBf+7?+KHd3}80yOqGF]BD=@|HQn+!eH;a');

define('SECRET_KEY', 'V&epQ8<j8=^Tpm*EUvw$|?t>k6zD.k?<,#0FtnxG$b!_[`-;[a>A~~QXds_xj:Q`');
define('AUTH_SALT', '11da4396f662c7a74c4a964e16cfb51e');
define('LOGGED_IN_SALT', '56d1e362e4d004b2ee19da2ca380b88c');

define('COOKIE_DOMAIN', '.yourdomain.com');
define('COOKIEPATH', '/');

define('USER_COOKIE', '3EC67573364C3D9A4ED82E1977D1407B');
define('PASS_COOKIE', '3157A4712DDD8777B7A86C64EC3547E6');
define('AUTH_COOKIE', 'DBC67C58653083F5313548C1593BE3FC');
define('SECURE_AUTH_COOKIE', '9330AF9D79B53117340DFC09D0C07064');
define('LOGGED_IN_COOKIE', '78876E53AC0622107F0B251492E345F2');
define('TEST_COOKIE', '84F4BA2A69803FB785FE0B9D675C9E86');
/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'b_';

/**
 * WordPress Localized Language, defaults to English.
 *
 * Change this to localize WordPress.  A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de.mo to wp-content/languages and set WPLANG to 'de' to enable German
 * language support.
 */
define ('WPLANG', '');

define('CUSTOM_USER_TABLE', 'a_users');
define('CUSTOM_USER_META_TABLE', 'a_usermeta');
define('CUSTOM_CAPABILITIES_PREFIX', 'a_');

define('OTHER_BLOGS_PREFIXES, 'a_,c_');

/* That's all, stop editing! Happy blogging. */

/** WordPress absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Important: group of defines in lines 45 - 62 has to be identical in wp-config.php of all installations.

All done. Login to one of the shared blogs and try to access another one. You'll see that you're already logged in!

2 thoughts on “Login once to access multiple WordPress installations”

  1. Using 2.92 and this worked brilliantly. Really a powerful capability for certain types of applications.

Leave a Reply

Links are not allowed in comment field!

Your email address will not be published. Required fields are marked *