Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.