Dismantle WordPress ‘Network of Sites’

Dismantling a WordPress ‘Network of Sites’, to extract a single site.

Recently I set up a WordPress ‘Network of Sites’ – but then realised I only really wanted a single-site install. This post details how I converted it into a single-site install.

Disclaimers

  • This seemed to work on the ‘subdirectory’ Network of Sites install I had set up, but it hasn’t been tested on a ‘subdomain’ set-up.
  • You may have plugins installed that may not work properly afterwards.
  • BACK UP your SITE FILES and DATABASE before attempting this.
  • This may break everything – make sure you have a good backup (and preferably make all your changes in a local server install)

Online information

If site you want to keep in your Network of Sites is the main site, then one of the following links will help you to convert it to a single-site install. But if the site you want to keep is a sub-site you added to your Network of Sites, then see if the rest of this post is any use.

1. Preparation

  1. Note part of the URL for the site you want to keep
    e.g. my site was in ‘www.something.co.uk/wp/identify/
  2. Note the ‘blog number’ of the site you want to keep
    In my ‘Network of Sites’ install, the site I wanted to keep was #2 (i.e. with database tables ‘wp_2_options’ etc.)
    If the blog you want to keep is the main one (i.e. not ‘_2’, ‘_3’ etc.) then the links in the ‘Online information’ section above are probably all you need.

1b. Back up

Back up all your sites files, and its full MySQL database.

2. Extracting a single site

2a. Top-level wp-config.php file

  1. Visit the Network Admin Dashboard ‘/wp-admin/network/’
  2. From the ‘Settings’ menu, choose ‘Network Setup’
  3. Use the displayed information as a guide to to remove the Network code from your top-level ‘wp-config.php’ file.
  4. Remove the ‘define(‘WP_ALLOW_MULTISITE’, true);’ line from your ‘wp-config.php’ file.

2b. Top-level .htaccess file

When you set up your network, you replaced all previous code in your .htaccess file with the code in ‘Network Setup’.

If you have a backup of the .htaccess file from before you enabled the ‘Network of Sites’, then reinstate it.

Or you could try deleting the file completely, if you didn’t need to add any code to it yourself.

2c. The blogs.dir directory

When you set up a Network of Sites, you add a new directory inside ‘wp-content’ named ‘blogs.dir’ to hold uploaded files.

To convert that structure back to the Single Site setup, remember which ‘blog number’ you want to convert (e.g. in the following I’m converting blog number 2), then:

  • Find the ‘/wp-content/blogs.dir/2/files’ directory
  • Move that final ‘files’ directory into the ‘/wp-content’ directory.
  • Delete the ‘blogs.dir’ directory

So you should end up with the following structure:

  • ‘/wp-content/files/2012/08/…

3. Database

Open the database associated with your install in phpMyAdmin.

3a. Delete tables

Delete the following tables:

  1. wp_blogs
  2. wp_blog_versions
  3. wp_registration_log
  4. wp_signups
  5. wp_site
  6. wp_sitemeta

(The purpose of each of these tables is noted in How to Disable a WordPress Network.)

Also delete the following ‘base’ tables (as we are going to rename all the ‘wp_2_commentmeta’ etc. tables to be the base tables ‘wp_commentmeta’ etc.)

  1. wp_commentmeta
  2. wp_comments
  3. wp_links
  4. wp_options
  5. wp_postmeta
  6. wp_posts
  7. wp_terms
  8. wp_term_relationships
  9. wp_term_taxonomy

3b. Rename tables

Find all the tables containing the ‘blog number’ you want to convert (e.g. ‘wp_2_commentmeta’) and remove the ‘2_’ from each one.

To rename a table in phpMyAdmin:

  1. Open the table
  2. Click ‘Operations’
  3. Rename the table in the ‘Table options’ section
  4. Click ‘Go’ in that section

3c. Find and replace

The safest way to alter values in the database seems to be to download the Search and Replace for WordPress Databases Script, and follow the instructions to find and replace values.

3b i. File paths

You need to change the file paths of files that were previously in the ‘blogs.dir’ structure.

Bearing in mind that the ‘blog number’ I want to make into a Single Site is number 2, I did the following:

In the ‘wp_posts’ and ‘wp_options’ tables:

  • Find ‘wp/identify/files’, replace with ‘wp/wp-content/files’

In the ‘wp_options’ table:

  • Find ‘blogs.dir/2/files’, replace with ‘files’

3c i. URLs

Update any instance of the old sub-directory URL in the database, with the top-level directory.

Bearing in mind my ‘blog URL’ was ‘www.something.co.uk/wp/identify’, I did the following:

In all tables:

  • Find ‘wp/identify’, replace with ‘wp’

So old URLs of the type ‘www.something.co.uk/wp/identify/2012/…’ would become ‘www.something.co.uk/wp/2012/…’

3c ii. Fields

You also need to do a find and replace on some meta_key values in the database.

Bearing in mind that the ‘blog number’ I want to make into a Single Site is number 2, I did the following:

In the ‘wp_usermeta’ table:

  • Find ‘wp_2_capabilities’, replace with ‘wp_capabilities’
  • Find ‘wp_2_user_level’, replace with ‘wp_user_level’
  • Find ‘wp_2_user-settings’, replace with ‘wp_user-settings’
  • Find ‘wp_2_user-settings-time’, replace with ‘wp_user-settings-time’
  • Find ‘wp_2_dashboard_quick_press_last_post_id’, replace with ‘wp_dashboard_quick_press_last_post_id’

In the ‘wp_options’ table:

  • Find ‘wp_2_user_roles’, replace with ‘wp_user_roles’

4. Refresh Permalinks

Finally, log into the Admin side of the site.

  1. Choose ‘Settings’, then ‘Permalinks’
  2. Note the current setting
  3. Switch to a different setting (e.g. ‘Default), and ‘Save Changes’
  4. Switch back to the original setting, and ‘Save Changes’

Leave a Reply

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