Skip to content

Instantly share code, notes, and snippets.

@jb-alvarado
Last active June 14, 2018 12:03
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 jb-alvarado/14ea1c7c638de3dfec1824cc86edc4cb to your computer and use it in GitHub Desktop.
Save jb-alvarado/14ea1c7c638de3dfec1824cc86edc4cb to your computer and use it in GitHub Desktop.
Disable specified WordPress plugins in your development environment. Useful for plugins that either make network calls you don't want when working (eg, auto-posting to Facebook), or for plugins that rely on services only available in production (eg, Varnish).
<?php
/**
* Disable specified plugins in your development 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 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 a server environment variable of WP_ENV, which I set
* to "development" or "production" in each particular server/environment.
*
* this plugin also redirect home and site url
*/
function dev_home() {
$url = 'https://' . $_SERVER['HTTP_HOST'];
return $url;
}
function dev_siteurl() {
$url = 'https://' . $_SERVER['HTTP_HOST'] . '/subfolder';
return $url;
}
// fixes the plugins_url
function dev_plugins_uri( $full_url, $path=NULL, $plugin=NULL ) {
return get_option( 'siteurl' ) . substr( $full_url, stripos( $full_url, PLUGINDIR ) - 1 );
}
if (!empty($_SERVER['WP_ENV']) && $_SERVER['WP_ENV'] == 'development') {
add_filter('pre_option_home', 'dev_home');
add_filter('pre_option_siteurl', 'dev_siteurl');
add_filter('plugins_url', 'dev_plugins_uri');
$plugins = array(
'w3-total-cache/w3-total-cache.php',
// 'varnish-http-purge/varnish-http-purge.php',
);
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
deactivate_plugins($plugins);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment