Recently a customer decided to move his installation of Awesome Support to another instance of WordPress but wanted to make sure that customers could still log into both sites without having to re-register. Here, in their own words is how they did it.
Install the new site using the SQL connection details from the existing site (Site A). This ensures that the new site tables and the old site tables are in the same database, making the data easier to share among the two sites. However, for the new site you must ensure you’re using a different table prefix. In this guide, we’ll use support_
During installation, you can create a new admin user for the new site.
Open the wp-config.php for Site B and add The following lines. You should replace wp_ with the table prefix used on Site A.
define('CUSTOM_USER_TABLE', 'wp_users'); define('CUSTOM_USER_META_TABLE', 'wp_usermeta');
On Site A’s wp-config.php locate the following lines and copy them on the wp-config.php of Site B, replacing what’s already there.
Note that both Site A and Site B will have hashes (different) where XXXX is shown below. You need to ensure that both sites have the same hashes.
define('AUTH_KEY', 'XXXX'); define('SECURE_AUTH_KEY', 'XXXX'); define('LOGGED_IN_KEY', 'XXXX'); define('NONCE_KEY', 'XXXX'); define('AUTH_SALT', 'XXXX'); define('SECURE_AUTH_SALT', 'XXXX'); define('LOGGED_IN_SALT', 'XXXX'); define('NONCE_SALT', 'XXXX');
Once this code block is saved on the file, the site will use the old tables to grant access. All of the users on SITE A will not have access to SITE B.
Each site has its own permissions. Those can be different form the other site and each user needs to have its permissions explicitly set on the usermeta table. This can be done programmatically or using admin
INSERT INTO wp_usermeta (user_id, meta_key, meta_value) VALUES (XXXX, "support_capabilities", "a:1:{s:13:"administrator";b:1;}")
You can navigate to the user details page of the user you’d like to change its role and update the role on the “Role” drop-down. Please note that the roles you set on each site will not propagate on any other sites, so a user can be an Administrator on one site and a simple user on another.
This is only possible if both sites are subdomains of the same domain for example Site A could be www.domain.com and Site B could be support.domain.com.
To achieve this, you need to add the following code on the wp-config.php for both Site A and Site B.
define('COOKIEHASH', md5('domain.com') ); define('COOKIE_DOMAIN', 'domain.com'); define('ADMIN_COOKIE_PATH', '/'); define('COOKIEPATH', '/'); define('SITECOOKIEPATH', '/');
The above code instructs the brower to store the cookies at the top domain (www is a subdomain).
Please note, you shouldn’t include a dot before domain.com. If you had .domain.com you’d probably run into issues.
You shouldn’t include any subfolders after the domain, so domain.com/folder would probably cause issues.
As we explained before, each user needs to have a capability for the specific site in order to gain access. This can be problematic if you already have a large number of users, as you’d have to write a new record on wp_usermeta for each user.
You could achieve by creating a script that will add a support_capabilities record for each user currently on the database. You’d then need to keep this in sync and each time a new user registers on Site A, you somehow give them access to Site B.
If you’d rather not worry about keeping the permissions in sync, you can grant access to any logged-in user to create tickets and view their own tickets. To do this, you can place the following filter inside your theme’s functions.php:
// Allow all users to have the specified capabilities. add_filter( 'user_has_cap', 'wpas_allow_all_to_create_ticket', 10, 3 ); function wpas_allow_all_to_create_ticket( $allcaps, $cap, $args ) { // Create an array to set the capabilities ALL users should have $allowedCapabilities = array ( 'attach_files', 'close_ticket', 'create_ticket', 'reply_ticket', 'view_ticket', 'read' ); // Loop through the must-have capabilities foreach ($allowedCapabilities as $capability) { // Check if we're asking about a must-have capability if ( $capability == $args[0] ) { // Add the missing capability $allcaps[$cap[0]] = true; } } return $allcaps; }