Tweaking WP Migrate DB Pro with Actions and Filters

Occasionally we’ll run into a situation where a slight change is required for WP Migrate DB Pro to work perfectly in a customer’s particular environment. To make this process a little easier we created a nifty utility plugin aimed at making slight tweaks to how WP Migrate DB Pro runs.

The aforementioned plugin is called WP Migrate DB Pro Tweaks and is available right now on GitHub.

The tweaks plugin includes documentation and example code for the most useful actions and filters found in WP Migrate DB Pro. Outlined below is two of the more notable actions and filters.

Migration Complete Action

Action name: wpmdb_migration_complete

This action makes it possible to run code immediately after a successful push or pull migration. In the example code we demonstrate sending an email to a particular person after your migration has completed.

Depending on how your environment is set up you could get even crazier with this action and do things like firing off git commands from within PHP.

For example, you could fire off a git push immediately after pushing your DB from staging to production, making both your DB and file system up to date.

Preserved Options Filter

Filter name: wpmdb_preserved_options

This filter makes it possible to preserve certain data within the wp_options table during a migration.

Let’s say you have a live website called “Acme Corp” and a development version of this website called “Acme Corp Development”. When you pull from the live website you might not want the development website’s title to be overridden during the migration.

By specifying the “blogname” option name in this filter you can effectively prevent that particular option in your wp_options table from being overridden.

Note that you must install the tweaks plugin on the website that you want the data to be preserved on, in this case it would be the development website.

For the full list of available actions and filters, be sure to check out the plugin on GitHub and please let us know us know if you’d like any action / filters added to upcoming versions of WP Migrate DB.

For some more examples, check out Ross McKay’s article.

About the Author

Chris Aprea

Chris wrote a ton of code and helped lots of customers for Delicious Brains during his 2-year stint with us. He has since moved on to other things.

  • chrismccoy

    awesome stuff, could use this for sending an email after completed