Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save santiazpi/0752df9d49bbe3375aa5b3185cec3bf8 to your computer and use it in GitHub Desktop.
Save santiazpi/0752df9d49bbe3375aa5b3185cec3bf8 to your computer and use it in GitHub Desktop.
staging-update-routine.php
<?php
/**
* Update site to use test mode in local and staging environments
*/
function prefix_env_settings() {
// If settings have already been updated, return early
if ( 1 == get_transient( 'staging-settings-updated' ) ) {
return;
}
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// If site has kinsta.cloud, it is staging.
if ( strpos( site_url(), 'kinsta.cloud' ) ) {
// Use Stripe in test mode
$woocommerce_stripe_settings = get_option( 'woocommerce_stripe_settings', array() );
if ( 'yes' != $woocommerce_stripe_settings['testmode'] ) {
$woocommerce_stripe_settings['testmode'] = 'yes';
update_option( 'woocommerce_stripe_settings', $woocommerce_stripe_settings );
}
// Disable outbound emails
//deactivate_plugins( '' );
activate_plugins( '/disable-emails/disable-emails.php' );
// Transient is set for 24 hours
set_transient( 'staging-settings-updated', 1, ( 60 * 60 * 24 ) );
error_log( 'staging-settings-updated' );
}
}
add_action( 'init', 'prefix_env_settings' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment