How to Merge Single WordPress Sites into a Multisite Network
Purpose
The purpose of this document is to explain a WordPress multisite, its use cases, installation processes, and how to migrate an existing site into a multisite network.
Audience
This document is intended for web developers, website administrators, and technical decision-makers considering implementing WordPress Multisite for their projects or clients. It is also beneficial for clients and stakeholders who wish to understand the capabilities and implications of using a multisite network to manage multiple websites under a single WordPress installation.
Multisite Definition
WordPress Multisite is a feature that allows you to create a “network” of subsites within a single instance of WordPress. This network shares a file system, and database, and is typically variations of the same domain. This means an administrator (called a SuperAdmin in a multisite environment) can log in to one site in the multisite network and access all sites under the same umbrella. This is useful for website managers who have to make updates to multiple websites as the process becomes easier to manage.
Further Reading:
How to Install and Setup WordPress Multisite Network by WP Beginner
Use Cases
When to use a multisite:
Clients who require multiple websites that share user data and information.
Clients who want ease of management across multiple websites with similar functionality where a website manager (SuperAdmin) is responsible for updating content across all sites.
Clients who hire Loop for multiple sites for their organization
Clients who are looking to build a new website from scratch and have a clear understanding of their long-term goals for the sites
When not to use a multisite:
To manage several unrelated client projects
For clients who foresee moving some or all of the subsites onto their own domain
With hosting providers that lack server requirements to run a multisite network
For clients who outsource sites within the multisite network for external management as consistency can become a problem when managing multiple development processes
When clients need plugin management at the subsite level by users who should not be granted SuperAdmin permission
Be cautious of clients who:
Require a long list of specialized plugins as they may not be compatible
Have websites built by external development teams as this can add complexity and increase the likelihood of potential data loss
Types of Multisites
Multi-sites can be configured in two ways, as subdomains (e.g. site.domain.com) or as a subdirectory (e.g. domain.com/site).
Important Notes:
Each site format offers certain search engine optimization benefits. Search engines read subdomains as separate sites on your web host; therefore, they maintain their page rank and authority, and multiple results for your domain are listed. Subdirectories are read as pages or sections of your main domain, help the main domain’s page rank and authority, and provide one result for your domain in search engines.
The benefits of each type of multisite depend on the specific needs of the client and the project and should be determined on a case-by-case basis.
Each site’s URL is saved in its tables in the database, after you pick which subsites you want to create, you cannot switch this without reinstalling the network.
Multisite Installation
A client’s hosting provider will determine the installation:
Steps to Migrating an Existing Site to a Multisite Network
Steps:
Confirm the multi-site installation is working
Create a blank site:
Create a new site via the Multisite administration panel (Sites –> Add New).
Enter a temporary subdomain when creating the site (e.g. migration1.example.org)
Edit the title to the new website domain.
Record the site ID as you will need it later.
Move the Plugins:
Determine which plugins need to be migrated to the multisite
Copy each plugin from your list above into the wp-content/plugins directory.
Move the Theme(s):
If each site uses a different parent and child theme, copy them both to the wp-content/themes directory.
If the sites use the same theme, rename each theme with a unique modifier before copying it to the wp-content/themes directory. Ensure to change both the theme folder name and the theme name in the master style.css file.
Record the site names as you will need them later.
Move each Uploads folder:
Each site has its own Uploads folder found at wp-content/uploads/sites/[N], where N is the ID of the site. Copy each Uploads folder to its corresponding location using the site IDs recorded in Step 2.
Note: Some plugins do not support Multisite and will want their uploads to live in the global
wp-content/uploads directory. Such situations have to be resolved on a case-by-case basis.
Migrating the database tables using phpMyAdmin:
For this step, we will need access to three databases: your multi-site database, your single-site database, and a temporary database that will be used to modify database tables.
Take a backup of the multi-site database.
Export the database of the first single site.
Import the single site database into a clean temporary database.
DO NOT import it into the live Multisite database, if you have done so, restore the multi-site database backup and start this step again.
In the temporary database, change all table name prefixes to wp_N_ where N is the site ID recorded in Step 2. Select the table and choose the “replace table prefix” option within the “With selected:” dropdown.
Next, change the prefix for user roles by running the SQL query below:
UPDATE wp_N_options SET option_name = 'wp_N_user_roles' WHERE option_name = 'oldprefix_user_roles';
Export all tables from the temporary database and import them into the multisite database.
Repeat this step for all single sites.
Update the wp-content/uploads directory folder path in the database by installing the WordPress plugin Better Search and Replace Pro and following the steps. The new uploads directory should be wp-content/uploads/sites/[N]
Merging the users
There's only one wp_users table and one wp_usermeta table in a multi-site database.
Users need to be merged from the wp_N_users table from the temporary database into the shared wp_users table in the multisite database.
For cases where there are many users the merging strategy is usually to offset their IDs by a large number (e.g. 10000)
Note: This update will also need to be applied to the wp_usermeta, wp_posts, and wp_comments tables as well as any plugin-specific tables that store the users’ IDs Update them by offsetting by the same number.
Resolve individual email and username conflicts using the following SQL query:
UPDATE wp_N_users SET ID = ID + 1000;
UPDATE wp_N_usermeta SET user_id = user_id + 1000;
UPDATE wp_N_posts SET post_author = post_author + 1000 WHERE post_author > 0;
UPDATE wp_N_comments SET user_id = user_id + 1000 WHERE user_id > 0;
Ensure users have the same roles and capabilities on the new
site in the Multisite network, as they had on the single site. Capabilities and roles are stored
in the wp_usermeta tables, along with possible other site-dependent keys.
A list of all possible keys that might need need to be updated can be found by running this query:
SELECT meta_key FROM wp_N_usermeta WHERE meta_key LIKE 'oldprefix_%' GROUP BY meta_key;
Run the query below on the usermeta table for each instance of the old prefix found from the result above.
To make the user updates run the following queries:
UPDATE wp_N_usermeta SET meta_key = 'wp_N_capabilities' WHERE meta_key = 'oldprefix_capabilities';
UPDATE wp_N_usermeta SET meta_key = 'wp_N_user_level' WHERE meta_key = 'oldprefix_user_level';
UPDATE wp_N_usermeta SET meta_key = 'wp_N_user-settings' WHERE meta_key = 'oldprefix_user-settings';
When done, you can cleanly insert all this data into the actual user tables by running this query:
INSERT INTO wp_users SELECT ID, user_login, user_pass, user_nicename, user_email, user_url, user_registered, user_activation_key, user_status, display_name, 0, 0 FROM wp_2_users;
INSERT INTO wp_usermeta SELECT '0', user_id, meta_key, meta_value FROM wp_N_usermeta;
Drop the wp_N_users and wp_N_usermeta tables and you’re done.
Wrapup
WordPress Multisite provides a robust solution for efficiently managing multiple websites within a single WordPress instance. By leveraging this feature, administrators can streamline updates, maintain consistency across sites, and simplify overall management tasks. However, it's essential to carefully assess the specific needs and long-term goals of each project to determine if a multisite network is the most suitable approach. Considering factors like hosting capabilities, plugin compatibility, and administrative requirements will help ensure a successful implementation that aligns with client objectives and enhances the overall web management experience.