Skip to content

Instantly share code, notes, and snippets.

@duanecilliers
Created April 5, 2017 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duanecilliers/e0cefea19ff29f986bd1311b0bfb0d31 to your computer and use it in GitHub Desktop.
Save duanecilliers/e0cefea19ff29f986bd1311b0bfb0d31 to your computer and use it in GitHub Desktop.
Deactivates plugins based on WP_ENV constant. Intended for use as an mu-plugin.
<?php
/**
* Deactivate plugins based environment (WP_ENV)
*
* Used to deactivate plugins only needed in specific environments, caching and security for example.
*
* @package Duanec\DeactivatePlugins
*/
namespace Duanec\DeactivatePlugins;
function deactivate( $file ) {
if ( is_plugin_active( $file ) ) {
deactivate_plugins( $file );
}
}
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
switch ( WP_ENV ) {
case 'development':
deactivate( 'w3-total-cache/w3-total-cache.php' );
deactivate( 'ithemes-security-pro/ithemes-security-pro.php' );
break;
case 'staging':
deactivate( 'w3-total-cache/w3-total-cache.php' );
break;
case 'production':
default:
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment