Disable plugins using WP Migrate DB

Set up rules to automatically disable plugins using WP Migrate DB’s find and replace feature.

Published in

,

Setting up development and testing environments for your sites is important to confirm updates and code changes don’t break your site, but they also duplicate plugins that are only relevant on the live site. Manually disabling these plugins every time you migrate a copy of your live database is annoying, especially when we can disable plugins using WP Migrate DB.

Back-ups and analytics plugins are examples of live-only plugins

The vast majority of back-up routines focus on making a copy of the code, database, and files on the live environment. That is your ultimate source of truth, and it does not make sense to bring that functionality down to a development or testing environment and potentially start backing up incomplete code or an out-of-date database.

The same is true for website analytics data. You don’t want to skew your numbers in weird ways by tracking visits to sites your development or test environments.

So how can we update our workflow to disable plugins using WP Migrate DB?

Replace the file path to the plugins main PHP file with and empty string

The find and replace rule you’ll need to add to your WP Migrate DB profile find the file path plugins main PHP for the plugin you want disabled, and replaces it with an empty string. The name of the main PHP file of a plugin is usually derived from the name of the plugin.

For example, let’s say you used UpdraftPlus Backup and Restoration plugin to create backups. The file path to its main PHP file, relative to the plugins directory, is updraftplus/updraftplus.php. Simply add a row to your WP Migrate DB profile with that file path in the Find column, and the Replace column blank.

disable-plugins-using-WP-Migrate-DB

This updates the active_plugins array in the database

WordPress stores the active plugin data in the active_plugins record within the wp_options table as a serialised string. The Migrate DB plugin is smart enough to know it is performing a find and replace on a serialised string and will unserialise it, run the find and replace, and reserialise the string.


Comments

Leave a Reply

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