Wednesday, February 9, 2011

WordPress plugin - Domains Update

I dared a few days ago to share a plugin I made with my work mates. It took me about 10 days to decide to do it (the sharing part). Last night my boss called me to ask me how to use it and in the end his conclusion was that it was not doing what I said it would...but, as usual, I had the "revelation" in the morning - meaning like 10 minutes ago.

So, I decided to put it here and see what kind of problems other people might have with it(omg...I am so evil).

What I pretend this plugin to do: updates values in database.

When you should use it: when you move your Wordpress site from one domain to another and you want to keep the database consistent.

Let's imagine the scenario when you move your Wordpress site from location A to B.

Options description:
1. Old domain - in our case would be A
2. New domain - in our case would be B
3. URL format - uncheck it if any of the domains does not have an URL format (e.g. localhost)
4. Select custom table(s) - when you press this button a list of the Wordpress' database tables is shown. When you select a table, a list of its columns is shown. Use this to update the values of old to new domain in other tables than wp_posts and other columns than wp_posts.guid and wp_posts.post_content (these are the default location of the update).
5.Update only custom tables - if this option is selected the default locations are skipped.
6. Run changes - runs the database updates.

Note 1: you can run this plugin multiple times.
Note 2: if you need to make updates in custom tables make sure you selected at least one table and for each table at least one column (otherwise it will tell you that there was no data to update).
Note 3: you might wonder why the plugin's name is Domains Switcher and in administrator's dashboard the name is Update Domains. Because I like to screw users' mind.

One more thing. The steps I follow when I need to move a Wordpress site from domain A to domain B and on domain A there is already content that needs to pe kept on domain B:
  1. Copy all needed files from A to B
  2. Export-import database from A to B
  3. On B, go to database and in table wp_options where column option_name has value siteurl and home the column option_value should have value A. Change it to B.
  4. On B, open file wp_config.php and update the information for database connection on B
  5. Enter wordpress admin on B (now you should be able to do that) and install and activate the Domains Switcher aka Update Domains plugin
  6. If all you need to update are posts and pages, run it with simplest configuration (without custom tables). The files uploaded and inserted into posts now will be taken from B, instead of A.
  7. If you used plugins which create their own tables, run the plugin against tables and columns that you know might contain URLs (e.g. for a slideshow plugin, it might keep in a custom table the links to images it uses)
  8. Sometimes plugins which do not create their own tables might insert links in column wp_postmeta.meta_value

You can download the plugin from here.

Known issue: Don't use it to update the information in cformsII plugin. It will alter the serialized string containing the cforms settings (and the plugin will stop from working). If you need to move cformsII to another domain, my suggestion is to install the plugin to the new locationa and backup-restore the forms from the old domain to the new one. If you have more than one form created with cformsII, just add new forms and backup-restore them. The global forms settings need to be update "manually" though.

No comments: