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 );
}
@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