Skip to content

Instantly share code, notes, and snippets.

@subharanjanm
Last active March 19, 2024 19:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save subharanjanm/4272d25a446fb2ca12a549a4a5662633 to your computer and use it in GitHub Desktop.
Save subharanjanm/4272d25a446fb2ca12a549a4a5662633 to your computer and use it in GitHub Desktop.
Deactivate certain plugins in the development/staging environment of WP Engine
<?php
/*
Plugin Name: Deactivate Certain Plugins - WPEngine Staging
Plugin URI: https://gist.github.com/subharanjanm/4272d25a446fb2ca12a549a4a5662633
Description: Deactivate certain plugins in the development/staging environment of WP Engine.
Version: 1.0
Author: Subharanjan
Author URI: https://gist.github.com/subharanjanm/4272d25a446fb2ca12a549a4a5662633
License: GPLv2
*/
/**
* Deactivate some plugins in the development/staging environment.
*
* This is a "Must-Use" plugin. Code here is loaded automatically before
* regular plugins load. This is the only place from which regular plugins
* can be disabled/decativated programatically.
*
* Place this code in a file in WP_CONTENT_DIR/mu-plugins or specify a
* custom location by setting the WPMU_PLUGIN_URL and WPMU_PLUGIN_DIR
* constants in wp-config.php.
*
* This code depends on server environment variable `IS_WPE_SNAPSHOT`.
* Also, you can use the variables like `HTTP_HOST` or `SERVER_NAME` to
* check for development/staging environment.
*/
if ( getenv( 'IS_WPE_SNAPSHOT' ) == 1 ) {
$plugins = array(
'coschedule-by-todaymade/tm-scheduler.php',
'google-analyticator/google-analyticator.php',
'hubspot-tracking-code/hubspot-tracking-code.php',
);
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
deactivate_plugins( $plugins );
}
@subharanjanm
Copy link
Author

Here is the complete list of WPEngine server environment variables.

Array
(
        [SERVER_SOFTWARE] => Apache
        [REQUEST_URI] => /

    [IS_WPE_SNAPSHOT] => 1
    [WPENGINE_PHPSESSIONS] => on
    [WPE_HEARTBEAT_AUTOSAVE_ONLY] => on
    [WPENGINE_FORCE_STRONG_PASSWORDS] => on
    [WPENGINE_CLEAR_EXPIRED_COOKIES] => off
    [WPENGINE_ACCOUNT] => yourwebsite
    [WPENGINE_SESSION_LOCKING] => on

        [HTTP_HOST] => yourwebsite.staging.wpengine.com
        [HTTP_X_LB_KEY] => yourwebsite
        [HTTP_X_IS_BOT] => 0
        [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5)
        [HTTP_X_FORWARDED_HOST] => yourwebsite.staging.wpengine.com
        [HTTP_CONNECTION] => close
        [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
        [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
        [HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch
        [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8
        [HTTP_COOKIE] => 
        [HTTP_IF_MODIFIED_SINCE] => May20165, 02 Maypm16 2016 09:26:09
        [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
        [SERVER_SIGNATURE] => 
        [SERVER_NAME] => yourwebsite.staging.wpengine.com
        [SERVER_ADDR] => 127.0.0.1
        [SERVER_PORT] => 80
        [REMOTE_ADDR] => 103.39.123.99
        [DOCUMENT_ROOT] => /nas/wp/www/staging/yourwebsite
        [REQUEST_SCHEME] => http
        [CONTEXT_PREFIX] => 
        [CONTEXT_DOCUMENT_ROOT] => /nas/wp/www/staging/yourwebsite
        [SERVER_ADMIN] => [no address given]
        [SCRIPT_FILENAME] => /nas/wp/www/staging/yourwebsite/index.php
        [REMOTE_PORT] => 18677
        [GATEWAY_INTERFACE] => CGI/1.1
        [SERVER_PROTOCOL] => HTTP/1.0
        [REQUEST_METHOD] => GET
        [QUERY_STRING] => 
        [SCRIPT_NAME] => /index.php
        [PHP_SELF] => /index.php
        [REQUEST_TIME_FLOAT] => 1463718261.92
        [REQUEST_TIME] => 1463718261
)

@subharanjanm
Copy link
Author

@JayHoltslander
Copy link

I forked this into a version that will disable plugins based upon the site's domain.

eg:
website.com = Active plugins.
website.stagingserver.com = Disabled plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment