Back to Top

How to share user data in multiple WordPress Installation?

Share user Data in multiple Wordpress Installation

Recently I am working on WordPress blogs in the same domain and want the user who registers on one to be able to log into the other without registering again. I have installed separate WordPress using the subdomain and I wanted to synchronize use data in all installation of WordPress.It means if a user logged into one installation, the user can access logged in information of other WordPress.

So Let’s understand how its possible in wordpress.

First of all, for that you need to have the same database for every WordPress installation with the different prefix.

NOTE: All installations of WordPress must have the same version.

Now, Open your second wordpress wp-config.php file and add following constant into it.

Here wp_ is prefix of main(first) WordPress installation, you can change it to your own prefix.

Well, Second WordPress should have different table prefix than the first one.you can change by placing below line of code.

However, you need to have same DB Connection information, AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY and NONCE_KEY as the first WordPress config file so each installation can authenticate your user login detail correctly across the different installation.

That’s it.now all of the WordPress installations are sharing the same user tables.But when you try to log in from other WordPress installation using main WordPress installation’s user detail, you will be logged into WordPress but not able to access wp-admin and get the error message ’You do not have sufficient permissions to access this page.‘.

Problem:

If you get error message “you do not have sufficient permission to access”,that means when it is trying to check user capability using the defined table prefix and which is not matched with the user meta of main WordPress installation.

Read: Post Autosave Interval in WordPress

This is because wordpress core file checking user capabilities and function for same is into wp-include/capabilities.php.Let’s see the function:

Here In above code, you will get $wpdb->prefix = your WordPress table prefix, but we are trying to access user and user meta table of main WordPress installation. That’s why its giving error.

Solution:

A solution of above issue is we manually customize core file of WordPress so replace the following line into function _init_caps.

But Do you think it is feasible solution?

No, Its not a feasible solution because you will have to change this code in every WordPress update..So here I come with the solution of the problem you get above.I will show you action hook which will update user capabilities into user meta table.

Read about:To get Current URL in wordpress

Above action hook will insert the record for other WordPress installation, you can go to your user meta table and see the meta_key $wpdb->prefix.’capabilities’.

You need to place above code into every WordPress theme’s function.php file.

I’m hoping that you’ve found this article helpful. Don’t hesitate to use this code in your WordPress projects and post your comments if you need help. As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

HTML5 Canvas Element Tutorial

Posted on 3 years ago

Bhumi

How to add child product in VirtueMart

Posted on 5 years ago

Bhumi

Two years blogiversary

Posted on 4 years ago

Bhumi

WordPress Plugin: Cool Flickr Slideshow

Posted on 6 years ago

Bhumi