Skip to content

Instantly share code, notes, and snippets.

@laurelstreng
Created June 1, 2020 15:19
Show Gist options
  • Save laurelstreng/a0ed49291590a7c97deb2876ac314890 to your computer and use it in GitHub Desktop.
Save laurelstreng/a0ed49291590a7c97deb2876ac314890 to your computer and use it in GitHub Desktop.
Wordpress mu-plugin to deactivate specific plugins on your local environment if defined in a wp-config-local.php file.
<?php
/*
Plugin Name: Deactivate Plugins Locally
Description: Deactivate specific plugins on your local environment if defined in a wp-config-local.php file.
Version: 1.0
*/
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
if ( defined( 'LOCAL_DISABLED_PLUGINS' ) ) { // If defined in wp-config-local.php
$plugins_to_disable = unserialize( LOCAL_DISABLED_PLUGINS );
if ( ! empty( $plugins_to_disable ) && is_array( $plugins_to_disable ) ) {
deactivate_plugins( $plugins_to_disable );
error_log( 'Locally disabled plugins: ' . var_export( $plugins_to_disable, true ) );
}
}
<?php
// Specify which plugins you want to disable for you local environment
define('LOCAL_DISABLED_PLUGINS', serialize([
'autoptimize/autoptimize.php',
'redirection/redirection.php',
'wp-smush-pro/wp-smush.php'
]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment