Skip to content

Instantly share code, notes, and snippets.

@devinsays
Last active February 7, 2021 15:02
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save devinsays/45958d6ed936aca18079 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' );
// Define test environments
$test_envs = array(
'https://example.dev', // Local
'https://example.staging.wpengine.com', // Staging
);
// If site is a test environment
if ( in_array( site_url(), $test_envs ) ) {
// 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( '/sendgrid-email-delivery-simplified/wpsendgrid.php' );
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