How to share WordPress user accounts across multiple blogs
Sharing WordPress accounts across multiple blogs is possible as of WordPress v2.6. This enables people to register on either one of your blogs and only have one account (username/password) to manage.
I've seen this question asked before and thought it would be helpful to write a tutorial about it. I personally prefer keeping the user accounts separate for added security and easier account management since I'd be the only one with access to my primary blog. It's up to you how you'd like to setup your sites though.
Example: This would be useful for someone running two instances of WordPress one of which is ClassiPress in a sub-directory of your primary WordPress site.
http://www.your-main-site.com" <-- your main instance of wordpress running the a different theme
http://www.your-main-site.com/classipress" <-- another instance of wordpress running classipress
So how can you do this? If you're starting out fresh and haven't yet installed a secondary blog, then this will be much easier. If not, you'll have to migrate your secondary database into your primary database (which is another tutorial).
1. Make sure you are using
WP v2.6 or greater
2. Both WordPress instances must be in the
same database
3. Add custom defines to the
wp-config.php of your secondary (child) blog
Let's assume your primary blog was installed with a table prefix of "wp_" and the secondary one with "wp2_". You'll then want to add the following code in
wp-config.php of the secondary installation.
Code:
define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USER_META_TABLE', 'wp_usermeta');
Install it right above the following line:
Code:
/* That's all, stop editing! Happy blogging. */
Now you are pointing your secondary blog to the primary WordPress user tables.
You can technically do this for as many instances of WordPress as you like but the key is to make sure they are all installed on the same database otherwise they won't be able to communicate. I'd also recommend making sure your versions of WordPress are in sync as well.
Some of you might get a "You do not have sufficient permissions to access this page" error message which means you are probably trying to do this across different domains. If you have a sub-directory like in the example above, it shouldn't be a problem.
From what I read online, you'll need to add this line to
wp-config.php of your secondary blog right below the other two entries you added above.
Code:
define('CUSTOM_CAPABILITIES_PREFIX', 'wp_');
Then you'll also need to modify a core WordPress file
wp-includes/capabilities.php (which I don't think is a good idea b/c you'll have to update it everytime you upgrade
WP)
Replace the following
Code:
$this->cap_key = $wpdb->prefix . 'capabilities';
with
Code:
if (defined ('CUSTOM_CAPABILITIES_PREFIX')) {
$this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities';
} else {
$this->cap_key = $wpdb->prefix . 'capabilities';
}
I have not personally tried this yet so I cannot provide any support if it doesn't work. If you do have questions either search Google or checkout the WordPress support site. Usually your question has been answered already.