Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Preserve some WordPress test/dev environment settings when pulling data from a production server with WP Migrate DB Pro
<?php
/*
Plugin Name: WP Migrate DB Fix Options
Plugin URI: https://gist.github.com/webaware/6959279
Description: Fix some options after a WP Migrate DB Pro migration, back to dev/test mode
Version: 1.0.0
Author: WebAware
Author URI: http://www.webaware.com.au/
@ref: http://snippets.webaware.com.au/snippets/use-wp-migrate-db-pro-and-keep-your-development-environment-settings
*/
/**
* tell WP Migrate DB Pro to preserve some options, so that we can stay in dev / test mode
* @param string $preserved_options
* @return string
*/
add_filter('wpmdb_preserved_options', function($preserved_options) {
$preserved_options = array_merge($preserved_options, array(
'active_plugins', // don't clobber dev/test plugins!
'admin_email', // don't send test emails to client!
'blog_public', // don't tell Google it can index test site!
));
return array_unique($preserved_options);
});
/**
* after WP Migrate DB Pro migration
* @param string $type
* @param string $location
*/
add_action('wpmdb_migration_complete', function($type, $location) {
// only for Pull migrations from another server
if ($type == 'pull') {
// force refresh of options
wp_cache_flush();
// WooCommerce eWAY settings
$settings = get_option('woocommerce_eway_payments_settings');
if (is_array($settings)) {
$settings['eway_customerid'] = '87654321';
$settings['eway_sandbox'] = 'yes';
update_option('woocommerce_eway_payments_settings', $settings);
}
// WooCommerce email settings
$settings = get_option('woocommerce_new_order_settings');
if (is_array($settings)) {
$settings['recipient'] = '';
update_option('woocommerce_new_order_settings', $settings);
}
}
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.