Safe Mode Warnings
-
We have a staging server that is not open to the public. We have recently been getting safe mode warnings. I have disabled woocommerce payments on our staging server but now there is no way to test product purchases there. Is there a proper way to have a staging environment with woocommerce payments? This seems to be a major shortcoming for this plugin.
We do set WP_ENVIRONMENT_TYPE to “staging” and JETPACK_STAGING_MODE to true.
The only other issue I see is that we have been defining WP_SITEURL and WP_HOME dynamically.
define('HTTP_HOST', $_SERVER['HTTP_HOST']); const WP_SITEURL = 'https://' . HTTP_HOST; const WP_HOME = 'https://' . HTTP_HOST; if ( preg_match( '!^(staging|dev|local)\..*$!i', HTTP_HOST, $matches ) ) { switch ($matches[1]) { case 'staging': define( 'WP_ENVIRONMENT_TYPE', 'staging' ); define( 'DB_NAME', 'XXXXXXXXXXXXX' ); define( 'DB_USER', 'XXXXXXXXXXXXX' ); define( 'DB_PASSWORD', 'XXXXXXXXXXXXX' ); break; case 'local': define( 'WP_ENVIRONMENT_TYPE', 'local' ); define( 'DB_NAME', 'XXXXXXXXXXXXX' ); define( 'DB_USER', 'XXXXXXXXXXXXX' ); define( 'DB_PASSWORD', 'XXXXXXXXXXXXX' ); break; default: define( 'WP_ENVIRONMENT_TYPE', 'development' ); define( 'DB_NAME', 'XXXXXXXXXXXXX' ); define( 'DB_USER', 'XXXXXXXXXXXXX' ); define( 'DB_PASSWORD', 'XXXXXXXXXXXXX' ); } define( 'JETPACK_STAGING_MODE', true ); } else { define('WP_ENVIRONMENT_TYPE', 'production'); define('DB_NAME', 'XXXXXXXXXXXXX' ); define('DB_USER', 'XXXXXXXXXXXXX' ); define('DB_PASSWORD', 'XXXXXXXXXXXXX' ); }
This has allowed us to use the same configuration file in all environments. This wasn’t an issue before. Based on https://woocommerce.com/document/payments/faq/safe-mode/#dynamic-site-urls we are changing to static definitions.
Will changing our config to the following still cause issues?
define('HTTP_HOST', $_SERVER['HTTP_HOST']); if ( preg_match( '!^(staging|dev|local)\..*$!i', HTTP_HOST, $matches ) ) { switch ($matches[1]) { case 'staging': define( 'WP_ENVIRONMENT_TYPE', 'staging' ); define( 'DB_NAME', 'XXXXXXXXXXXXX' ); define( 'DB_USER', 'XXXXXXXXXXXXX' ); define( 'DB_PASSWORD', 'XXXXXXXXXXXXX' ); define( 'WP_SITEURL', 'https://staging.example.com' ); define( 'WP_HOME', 'https://staging.example.com' ); break; case 'local': define( 'WP_ENVIRONMENT_TYPE', 'local' ); define( 'DB_NAME', 'XXXXXXXXXXXXX' ); define( 'DB_USER', 'XXXXXXXXXXXXX' ); define( 'DB_PASSWORD', 'XXXXXXXXXXXXX' ); define( 'WP_SITEURL', 'https://local.example.com' ); define( 'WP_HOME', 'https://local.example.com' ); break; default: define( 'WP_ENVIRONMENT_TYPE', 'development' ); define( 'DB_NAME', 'XXXXXXXXXXXXX' ); define( 'DB_USER', 'XXXXXXXXXXXXX' ); define( 'DB_PASSWORD', 'XXXXXXXXXXXXX' ); define( 'WP_SITEURL', 'https://dev.example.com' ); define( 'WP_HOME', 'https://dev.example.com' ); } define( 'JETPACK_STAGING_MODE', true ); } else { define( 'WP_ENVIRONMENT_TYPE', 'production' ); define( 'DB_NAME', 'XXXXXXXXXXXXX' ); define( 'DB_USER', 'XXXXXXXXXXXXX' ); define( 'DB_PASSWORD', 'XXXXXXXXXXXXX' ); define( 'WP_SITEURL', 'https://example.com' ); define( 'WP_HOME', 'https://example.com' ); }
Is there a proper way to handle multiple environments? We do not want to update production without first updating our development/test environments first.
Thank you.
- The topic ‘Safe Mode Warnings’ is closed to new replies.