Created
October 25, 2023 14:37
-
-
Save georgestephanis/47ab2c43d3989712720632a1bb8ad68f to your computer and use it in GitHub Desktop.
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 | |
/** | |
* This code's purpose is to ensure that any clones of a | |
* site hosted on Atomic are run safely so that processes | |
* meant to happen only on production (emailing customers, | |
* api calls, cron jobs, etc) are properly removed and that | |
* Safety Net is appropriately configured. | |
*/ | |
$cached_ATOMIC_SITE_ID = get_option( 'team51_ATOMIC_SITE_ID' ); | |
if ( empty( $cached_ATOMIC_SITE_ID ) ) { | |
// Nothing was cached in the options table. | |
// Either the option was deleted, or this code was just added. | |
if ( empty( $_SERVER['ATOMIC_SITE_ID'] ) ) { | |
// The code is not running in an Atomic Environment, and | |
// there is no record of it having run under Atomic in | |
// the past. Just return out of this file and do nothing! | |
return; | |
} | |
// If we have an ATOMIC_SITE_ID but it isn't cached in our | |
// options table, then just write it to the options table and | |
// carry on with loading the site. | |
update_option( 'team51_ATOMIC_SITE_ID', $_SERVER['ATOMIC_SITE_ID'] ); | |
return; | |
} elseif ( empty( $_SERVER['ATOMIC_SITE_ID'] ) || $_SERVER['ATOMIC_SITE_ID'] !== $cached_ATOMIC_SITE_ID ) { | |
// We have a cached site id from the options table (as we passed | |
// the first conditional), but there is no site id environment | |
// variable, or there is and it is different than the cached | |
// site id -- WordPress is running in an unexpected environment. | |
// Check for Safety Net being active and having run? If we exit | |
// here, perhaps exit with a form for cli / html that prompts the | |
// user to install Safety Net and run it. Killing execution here, | |
// early, will prevent WordPress from doing dangerous actions from | |
// a development environment unintentionally. | |
wp_die( 'It looks like this site is running in an unexpected environment. ' . | |
'Please run Safety Net to make sure all personal information is ' . | |
'sanitized, the Jetpack connection is reset, outbound email is ' . | |
'gagged appropriately, and Production API keys are purged.' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment