ezMigrate plugin for WordPress
While setting up a development environment last month for an extensive blog using WordPress I once more encountered a problem which I ran up against every single time I had worked with WordPress. The absolute urls stored in constants, options and post contents got in my way again. Now it was the time to find a solution for this and take matters into my own hands.
Introduction
At triptic we like to develop our projects on a development server using a Version Control System. That way we can work with multiple people on the same project and test it before putting it on a production server. We all have our own checkout of a project and our own url through which we can view our checkout of the project so we can test our code before committing it to the repository. We also like to use the same single database for all developers so we can look at the same content and the same settings. I know there are reasons not to do this, but for smaller projects it’s just a fast way of getting things done. When a project is finished we migrate everything to a test server so the customer can have a look at it before we move it to the production server. Because development on a project is never finished we need to be able to make code changes on the development server. We also need to be able to test it with the newest content, so we often move the production database back to the development database before putting the newest code onto the production server.
Short version:
- Our projects need to migrate a lot
- On a development server our projects need to be available through multiple urls at the same time
Our own solution
This is why our home grown Content Management System determines its location on the fly and puts a <base href=”"> in the header of every page. Additionally the current directory within PHP is always set to the root location of the CMS. This way we can use relative urls and relative locations everywhere in the code and we can move projects anywhere without the need to change anything. But sometimes our own CMS is just not the right tool for the job and we need to use some other framework or CMS.
The problem with WordPress
When we need to create a blog the obvious choice is to use WordPress. Unfortunately it doesn’t have the same characteristics as our own CMS that allow it to migrate so easily. Absolute paths our stored in the database which need to be changed every time the project changes location. There are ways to do search and replaces and there even are plugins that help you to do this, but I really don’t like doing this every single time the project switches location. It also isn’t possible to view the project through multiple urls at the same time which doesn’t allow for development the way we’d like to.
So…, I went on a mission to fix this.
The result:
the ezMigrate plugin for WordPress
ezMigrate plugin
The ezMigrate plugin does the following things:
- It determines the root url of the blog.
- It replaces the options “siteurl”, “home”, “upload_path” and “fileupload_url” to the correct values, independent of their values stored inside the database.
- When not already set in wp-config.php it sets the constants WP_CONTENT_URL, COOKIEPATH and SITECOOKIEPATH to the correct values.
- When a post is saved into the database it replaces all root urls in href and src attributes with a placeholder. (This is also done for all posts when the plugin is activated).
- When a post is retrieved from the database it replaces all placeholders with the current calculated root url. (This is also done for all posts when the plugin is deactivated).
This way you don’t need to do anything when you migrate your blog and you can even make your blog accessible through multiple urls. It made life for me and the other developers at triptic a lot easier when we need to develop blogs using wordpress.
What this plugin doesn’t do (but might do in the future):
- Put a <base href=”"> in the header of your template. You can easily do this yourself by placing
<base href="<?php echo ezMigrate_getFullUrl();?>/" />right after the <head> tag in the header.php file of your theme. - Replace urls outside of the four mentioned options or outside of href and src attributes in posts. But so far it has been sufficient for my projects.
- Make changes that might be necessary in the .htaccess file.
This plugin is a step towards setting up a development environment with a VCS and multiple developers but there are still some problems to overcome. The contents of the .htaccess file are still dependent on the location and you might not wish to leave the .htaccess file sitting outside of the repository. I will write more about how to solve this in a future post, as well as what to do with the wp-content directory.
Download the ezMigrate plugin for WordPress and follow the installation instructions.
Comments on the usage of this plugin and suggestions are greatly appreciated.
Related articles:


require_once ABSPATH.’wp-content/plugins/ezMigrate/includes/config_include.php’;
should be
require_once ABSPATH.’wp-content/plugins/ezmigrate/includes/config_include.php’;
notice the m in “ezmigrate” is not capitalized otherwise the install went swimmingly
@desee:
Thank you for your comment. I have updated the installation instructions.
Thanks the author for article. The main thing do not forget about users, and continue in the same spirit.
The subject is fully clear but why does the text lack clarity? But in general your blog is great.
Is this important for normal everyday blog users? I’m just curious. I chanced on this site and It was like reading another language. Sheesh. Why multiple url’s? Why do you need to see the same page at the same time thru different url’s? Is that even what that means? I have no idea. I read this and thought …what? Wow, few things have sounded so confusing.
As a simple blogger….VERY SIMPLE….hehe…is using this ezmigrate of any benefit to me and others like me? Is this plugin only for people with development stuff going on? I’m just so derned curious.
Thanks
@Mesha:
This plugin does make a development cycle easier but can also be of use when you like to change the url of your blog. Next weekend I will write an easier post about how to do that with the ezMigrate plugin.
If you don’t want to change your url and you are just a simple blogger without any development going on then this post and plugin is not meant for you.
I repeatedly get a fatal error after installation, producing the error message from ezMigrate_getUrl() function.
I’ve checked my work repeatedly and have also tried some minor modifications of syntax.
@CK MacLeod
What is the exact error message you are getting?
ERROR in ezMigrate_getUrl: current script /home/users/web/b1618/sl.ckmaccom/public_html/thewholething/wp-admin could not be found in your wordpress directory /hermes/bosweb/web161/b1618/sl.ckmaccom/public_html/thewholething/
Obviously most of it is just my server/address. I believe it’s just the error message from the getUrl() function as above.
@CK MacLeod:
It’s probably due to a symlink somewhere in your wordpress path. It seems __FILE__ doesn’t handle symlinks the same way $_SERVER['SCRIPT_FILENAME'] does. I will try to write a fix for this.
Onno Morsman,
I look forward to the future update!
This sounds like a great plugin as I prefer to work on dev environment before tagging and sending it to live.
However on the project I am trying to use this on, as soon as its activated the admin interface loses all styling. Closer inspection reveals that CSS links change from:
http://mysite.com/wp-admin/load-styles.php
http://mysite.com/wp-includes/js/thickbox/thickbox.css
to references like this:
http://mysite.com/wp-admi/wp-admin/load-styles.php
http://mysite.com/wp-admi/wp-includes/js/thickbox/thickbox.css
Notice the extra “wp-admi” added in there. I’m not very cluey with the wordpress system, but don’t think I have made any changes that would have done this. Can you please help?
@Fester: In the new version 0.9 a critical fix has been made. Please try this version and let me now if you still experience any problems.
Just found this article several months after it was originally written, so I hope you are still monitoring to answer a question.
I need to set up a number of WordPress blogs (10 to start with, more later), all hosted separately, but all VERY similar in look, feel & structure.
Ideally I would like to be able to set up one “template” blog with the desired configuration, a basic post, a couple of static pages such as “About” & “Contact Us”, all the necessary plug-ins & widgets, and so on — then clone it.
Then I would just install the clone into each of the other hosted domains.
So my question is: is the ezMigrate plugin the tool for me?
TIA
@Zapod: cloning is the same as moving. The only difference is you just don’t remove the old installation after you’re finished. So my answer would be: Yes, you can use ezMigrate to clone wordpress installations.
Please also have a look at: Moving WordPress using the ezMigrate plugin. This article is a bit more clear on how to use this plugin.
hi,
first of all thanks for the plugin! i had some trouble when moving my site with your plugin though. it took me quite a while to figure it out:
1. in ezMigrate.php
i replaced the first if-block with this, because somehow my server misinterpreted the closing “?>” within the {} after the if statement. I changed the whole block to this:
if (!function_exists(‘ezMigrate_getUrl’)) {
echo “ERROR in ezMigrate plugin:
Please insert the following code into your wp-config.php at a line before the line `require_once(ABSPATH . ‘wp-settings.php’);` :
`require_once ABSPATH.’wp-content/plugins/ezmigrate/includes/config_include.php’;`”;
exit;
}
2. in both ezMigrate.php and config_include.php:
I had to replace “<?" by "<?php" in order to work. I don't know why this is, but it did'nt work without the php.
Now it works perfectly.
@elm: This happened when the short_open_tag php.ini directive was set to off. It is fixed in version 0.10 of the plugin.
Hello Onno,
Does this plugin would work in a mutisite setup (3.2.x). If yes, need to install network or per site?
Thanks,
Alex
@Alex: good question. Unfortunately, I haven’t tried this yet. Because this plugin requires changes in wp-config, my first guess is that it would be necessary to install it on all sites, but I am not sure about this and whether it would work at all.
I will have a look at this in the future.