10+
March 23, 2019
February 9, 2019
Simply define your production url in settings and copy your site to your staging instance without fear. The staging site won’t send any emails and won’t process any payments.
If you host your site on a managed host that provides a staging instance (WP Engine, Siteground, and others), or if you run a staging instance for a self-hosted website, you may have found that WordPress and WooCommerce will automatically send emails and process payments from the staging site. Whenever you clone your production site to your staging site, you would normally need to complete a number of steps to make your site “safe for staging.”
Instead, install this plugin in production, set the production URL, and safely copy your site to and from staging. No other steps needed!
/wp-content/plugins//wp-admin/plugins.php/wp-admin/options-general.php?page=safe-stagingThe filter safe_staging_is_production will let you change what the plugin sees as the production site.
For example, the filter below will let you support an alternative production URL.
/**
* Change whether Safe Staging thinks the current site
* is the production site.
*
* @param bool $is_prod Is this the production site.
* @return bool Whether we should treat this as an alternative production site.
*/
add_filter(
'safe_staging_is_production',
function( $is_prod ) {
$alternative_prod_url = 'https://myothersite.com';
if ( site_url() === $alternative_prod_url ) {
$is_prod = true;
}
return $is_prod;
}
);
The filter safe_staging_is_whitelist_email will let you intervene just before an email is blocked.
For example, the filter below will let you support an alternative production URL.
/**
* Determine whether a particular email should be sent.
*
* In this case we test if the to recipient is our admin address.
*
* @param bool $whitelisted Should the email actually send.
* @param object $this Instance of the Fake PHPMailer class.
* @return bool Whitelist value tested against the recipient.
*/
add_filter(
'safe_staging_is_whitelist_email'
function( $whitelisted, $phpmailer ) {
if ( 'admin@mysite.com' === $phpmailer->getToAddresses() ) {
$whitelisted = true;
}
return $whitelisted;
},
10,
2
);
The filter safe_staging_checkout_notice will let you override the message shown on the cart and checkout pages.
/**
* Change the warning message that gets displayed on the checkout page
* of staging sites.
*
* @return string New message to show on the checkout page.
*/
add_filter(
'safe_staging_checkout_notice',
function() {
return 'You\'ve found our staging site! You might want to go back to the production site.';
}
)