Forked from markjaquith/disable-plugins-when-doing-local-dev.php
Last active
August 8, 2016 06:49
-
-
Save jb510/440095d74d68b6896a06 to your computer and use it in GitHub Desktop.
Jaquith's Disabled plugins on local/staging, with added filter to pre-set blog privacy to hide from search engines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Disable plugins when doing local dev | |
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify | |
Version: 0.1 | |
License: GPL version 2 or any later version | |
Author: Mark Jaquith | |
Author URI: http://coveredwebservices.com/ | |
*/ | |
class CWS_Disable_Plugins_When_Local_Dev { | |
static $instance; | |
private $disabled = array(); | |
/** | |
* Sets up the options filter, and optionally handles an array of plugins to disable | |
* @param array $disables Optional array of plugin filenames to disable | |
*/ | |
public function __construct( Array $disables = NULL) { | |
// Handle what was passed in | |
if ( is_array( $disables ) ) { | |
foreach ( $disables as $disable ) | |
$this->disable( $disable ); | |
} | |
// Add the filter | |
add_filter( 'option_active_plugins', array( $this, 'do_disabling' ) ); | |
// Allow other plugins to access this instance | |
self::$instance = $this; | |
} | |
/** | |
* Adds a filename to the list of plugins to disable | |
*/ | |
public function disable( $file ) { | |
$this->disabled[] = $file; | |
} | |
/** | |
* Hooks in to the option_active_plugins filter and does the disabling | |
* @param array $plugins WP-provided list of plugin filenames | |
* @return array The filtered array of plugin filenames | |
*/ | |
public function do_disabling( $plugins ) { | |
if ( count( $this->disabled ) ) { | |
foreach ( (array) $this->disabled as $plugin ) { | |
$key = array_search( $plugin, $plugins ); | |
if ( false !== $key ) | |
unset( $plugins[$key] ); | |
} | |
} | |
return $plugins; | |
} | |
} | |
/* Begin customization */ | |
/* | |
* For programmatic disabling, you can initialize the object (e.g. as $_localdev) then do: | |
* $_localdev->disable( 'vaultpress.php' ); | |
*/ | |
if ( defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV ) { | |
add_filter( 'pre_option_blog_public', '__return_zero' ); // Force blog privacy, robots no-follow metatag | |
new CWS_Disable_Plugins_When_Local_Dev( array( 'w3-total-cache/w3-total-cache.php', 'wp-super-cache/wp-cache.php', 'iwp-client/init.php', 'wordpress-https/wordpress-https.php', 'cloudflare/cloudflare.php', 'WPEngine-Clear-URL-Cache/wpengine-clear-url-cache.php' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment