Or how to create a blog network with out WordPress Multi-User.
Almost 2 years ago, I was charged with the duty of building an integrated Blog network with WordPress, for the Parents Everywhere Network. WordPress MU wasn’t quite ready for prime time, as most plugins hadn’t been ported over, and documentation was sparse, and only the bravest of souls wanted to tangle with it. Remember, this was back before WP and MU development were in sync. So I had to come up with another way.
That’s when I ran across these little known wp-config.php keys: CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE. By setting these keys to the same values in all of your wp-config.php you can have multiple WordPress installs share the same user tables and essentially create a nearly-perfect single sign-on system for your blog network.
There are limitations, of course, but by and large the shared users table trick works like a charm. I’ll show you how to set it up yourself for some newly installed blogs. You can convert existing blogs over, but that takes more DB fiddling then I’ll go into in this article. The biggest limitation is that all of the blogs have to be installed in the same Database. However, they can be on different servers, as long as they can all talk to the same Database.
- First, install your primary blog as normal, and set your CUSTOM_USER* keys in your wp-config:
define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USER_META_TABLE', 'wp_usermeta');
- Second, create the wp-config.php for your second blog, using the same DB Connection information. You also need to set AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY, and the CUSTOM_USER* keys to the same value as the first. You will also need to set $table_prefix to a unique value.
- Install the second blog and instead of getting a random password for the admin user, it should tell you that it found the user and is using that password.
- Rinse and Repeat steps 2 and 3 until all blogs are successfully installed.
Now that all of the blogs are sharing the same user tables, your admin login will work on all of them, and remain the same, even when changing the password and other meta data (i.e. name, etc), but all other settings will remain distinct for all of the other blogs. However, if you allow (or force) users to sign up to comment or do other things on your blog, then you will run into the second limitation of this trick – users only get a Role assigned on the blog that they signed up on. Their account is in table and accessible to the other blogs, they just don’t have any privledges. In other words, they are orphans. This can be fixed manually in the User management screens, or automatically via a plugin.
The final limitation, and this isn’t the fault of WordPress but how the internet works, is that because your blogs are (probably) on separate domains, cookies can’t be shared between them easily and hence users will have to log-in to each blog they visit. A small price to pay for one of the cooler hidden features of WordPress.
This is the professional blog of Eric Marden, a veteran web developer, entrepreneur, and inspirational speaker.
If you're new here, please subscribe to my RSS feed. You'll get a blend of tech news, analysis, inspirational essays, and much more. Subscribe today.
Thank you for this explanation
“cookies can’t be shared between them easily”
There is a procedure here to enable cookie sharing between WP subdirectories or WP subdomains : http://techblog.touchbasic.com/html/single-unified-login-for-multiple-wordpress-2-8-installs-in-subdirectories-using-cookies/
Tested with success on WP 2.8.5
Sub-directories sure, but not on separate domains, which is how I set it up when I originally did this for the client.
Great Link, though!
~/e
I had multiple installs in different databases and combined them all into my main db using a different table prefix for each. I have done all the necessary editing in the wp-config.php file, and am now not able to log into my other secondary blog. It is saying that I dont have sufficient permissions. I found a code change for the capabilities file, but that has not proven successful either. Do you know of a way to fix this problem? The username/passwords for all of my blogs were setup as the same, but are all different in the user database tables due to the hash system. I have tried copying the pw listed in the original installations’ user table to the secondary user table, but it’s not working either. Suggestions?
You will need to start over with your blogs separated. Install a new blog with a unique table prefix, and get it to ‘hook’ into the admin account you have now, as explained in this blog. Then import the content from the 2nd blog into this new instance, and you should be good to go. I’m pretty sure only new blog installs can use the Shared Users Table trick.