WordPress Blogs Same Users

Posted by on Mar 1, 2010 in Bits, Blog | 1 comment

WordPress Blogs Same Users

Another guide i thought i would commit to my blog for the future. These code snippets allow you to had any number of wp blogs and use the wordpress users all from the same blog.

To start with install the 1st blog as per the instructions. Make the table prefix something you will recognise eg “wp_main_” as you will have to refer back to it.

Once your fist blog has been installed, install your 2nd wordpress blog in a different directory. Make the table prefix something differnt ot the main/1st blog you made. But in the same database. Once the setup is complete, download the wp_config file and edit it.

Add:

define(‘CUSTOM_USER_TABLE’, ‘<-YOUR MAIN USERS TABLE eg:wp_users->’);
define(‘CUSTOM_USER_META_TABLE’, ‘<-YOUR MAIN USERS TABLE eg:wp_usermeta->’);
define(‘CUSTOM_CAPABILITIES_PREFIX’, <-YOUR MAIN USERS PREFIX eg:’wp_->’);

This lets the second blog use the tables relating to the user from the main blog.

You also need to make the authentication keys the same. Copy these from the wp_config file of your main blog:

define(‘AUTH_KEY’, ‘<-YOUR KEY->’);
define(‘SECURE_AUTH_KEY’, ‘<-YOUR KEY->’);
define(‘LOGGED_IN_KEY’, ‘<-YOUR KEY->’);

Now we are done with the config file. Now you need to edit a file called capabilities.php, this is found in your /includes/ folder.

Find: $this->cap_key = $wpdb->prefix . ‘capabilities’;

And Replace: //    $this->cap_key = $wpdb->prefix . ‘capabilities’; added custom below

if (defined (‘CUSTOM_CAPABILITIES_PREFIX’)) {
$this->cap_key = CUSTOM_CAPABILITIES_PREFIX . ‘capabilities’;
}
else {    $this->cap_key = $wpdb->prefix . ‘capabilities’;
}

$this->caps = &$this->{$this->cap_key};
if ( ! is_array( $this->caps ) )
$this->caps = array();
$this->get_role_caps();
}

Save these files down and upload them to your server. All should now be working. This can be done with any number of additional blogs.

Please remember you will need to change the capabilities.php file each time you upgrade to add the new lines.

Bookmark this page for next time ou upgrade!

One Comment

  1. Thanks for the helpful post! I would not have gotten this otherwise!

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>