Last active
November 7, 2018 00:25
-
-
Save webaware/6959279 to your computer and use it in GitHub Desktop.
Preserve some WordPress test/dev environment settings when pulling data from a production server with WP Migrate DB Pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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