Skip to content

Instantly share code, notes, and snippets.

@aaemnnosttv
Created May 20, 2014 18:01
Show Gist options
  • Select an option

  • Save aaemnnosttv/67a03302c51f09a5f669 to your computer and use it in GitHub Desktop.

Select an option

Save aaemnnosttv/67a03302c51f09a5f669 to your computer and use it in GitHub Desktop.
Soft Disable All WP Plugins
<?php
/**
* Plugin Name: Soft disable all WP plugins
* Author: Evan Mattson (@aaemnnosttv)
* Description: Allows all plugins to be softly disabled and re-enabled using a single constant.
* Version: 1.0
*
* Usage: Install this under mu-plugins/, and define('SOFT_DISABLE_PLUGINS', true) to soft disable all plugins.
* Delete/comment-out the constant definition or set to false to restore all plugins to their previous active states.
*
* For WordPress 3.0 and above
*/
if ( !defined('SOFT_DISABLE_PLUGINS') )
define('SOFT_DISABLE_PLUGINS', false);
if ( SOFT_DISABLE_PLUGINS )
{
add_filter('pre_option_active_plugins' , '__return_empty_array' , 9999);
// This next filter prevents the active_plugins setting from being updated (wiped out) while we have them all disabled.
// update_option will not update an option if the new value === old value.
add_filter('pre_update_option_active_plugins' , '__return_empty_array' , 9999);
}
@ahansson89

Copy link
Copy Markdown

Nice!!

@jacmart

jacmart commented Mar 10, 2015

Copy link
Copy Markdown

Hello and thanks for sharing.

One ting puzzles me: would that be a useful plugin to convert an existing single WP site into a multi-site installation? They recommend to close all plugins for that purpose - which is a bummer because of several settings getting lost I guess - but I'm not sure if keeping those settings in the database would ruin the multi-site conversion... Perhaps you have an idea? Cheers.

@aaemnnosttv

Copy link
Copy Markdown
Author

This code isn't designed to work with multisite, but it could be used for that purpose I suppose. It does not however affect network-enabled plugins for a site already running as a multisite.

@crzyhrse

Copy link
Copy Markdown

Thank you for this, it is much appreciated...

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