• Resolved Dave Lozier

    (@dave-lozier)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Chris Moreira – a11n

    (@chrism245)

    Hello!

    Sorry about the delay on getting back to you about this!

    Have you done the changes to the configuration file? Does the problem persists?

    Hi @dave-lozier

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    Thread Starter Dave Lozier

    (@dave-lozier)

    Hi @maykato

    I wouldn’t call it resolved but more as a work-around. I prefer a more dynamic approach to environments to make development easier. My solution does work. It is just not as flexible as it could be. I am assuming that there is no “proper” way to do this.

    Cheers,
    ~Dave

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Safe Mode Warnings’ is closed to new replies.