Issues with Staging Site

I want to exclude some things running (like defender pro notifications) on the staging site, but not on production.

  • Dimitris
    • Support Star

    Hello there Matthew

    You can use constants for staging-specific functions, but you should be careful and switch the values of them before pushing staging to production.

    For example, you can use:

    if (defined('WP_DEBUG') && true === WP_DEBUG) {
    /* My Custom Debug/Development configs here*/
    }

    or any other custom constant of yours:

    if (defined('MY_CUSTOM_CONSTANT') && true === MY_CUSTOM_CONSTANT) {
    /* My Custom Debug/Development configs here*/
    }

    In these examples, you should change TRUE to FALSE, before pushing staging to production. That’s because this action will replace all files and DB on the production site. I quote the notice as found in the Staging tab:

    Moving your staging changes your production site will result in overwriting any files or database changes. You can optionally move only portions of your site if you do not wish to overwrite everything.

    Having said that, let us know if you need assistance about making any specific changes into staging, like hiding Defender’s notification, so we can provide the exact code.

    Thank you,

    Dimitris

  • Matthew
    • Flash Drive

    Hi Thank you for your response, however this really isn’t what I was looking for. I’m looking for a solution specifically so I don’t have to manually make changes when syncing back-and-forth between production and staging.

    Perhaps something like:

    if ( $_ENV['WPMUDEV_ENV'] === 'PRODUCTION' ) {
    // Do stuff in production environment
    } else{
    // Do stuff in staging environment
    }

  • Dimitris
    • Support Star

    Hello there Matthew

    Unfortunately, there aren’t any such global vars that you could use. If you don’t want to use a workaround like the one I shared above, which require a manual change before syncing, you could use another approach and check the domain name that made the request. If it’s the staging site, then you can add any functions needed for staging only. Here’s an example:

    if ( strpos( $_SERVER['HTTP_HOST'], 'staging') !== false ) {
    error_log( 'I am using staging!' );
    }

    Warm regards,

    Dimitris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.