Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rniswonger/0c42cb16b1a96dde65630db140c99073 to your computer and use it in GitHub Desktop.
Save rniswonger/0c42cb16b1a96dde65630db140c99073 to your computer and use it in GitHub Desktop.
WordPress: Disable/activate plugins in development environment
<?php
/**
* Setup development environment by manipulating plugin activation
* Replace the dev URLs and plugin paths accordingly
*/
function mysite_development_environment_setup() {
// define the development sites
$dev_envs = array(
'http://localhost:8888',
'http://mysite.localhost',
);
if ( in_array( site_url(), $dev_envs ) ) :
// Skip plguin actions if they were performed recently
if ( ! get_transient( 'dev-env-updated' ) ) {
// deactivate plugins
$unwanted_plugins = array(
'/ithemes-security-pro/ithemes-security-pro.php',
'/w3-total-cache/w3-total-cache.php',
'/updraftplus/updraftplus.php',
'/backupbuddy/backupbuddy.php',
'/sg-cachepress/sg-cachepress.php',
'/loginizer/loginizer.php',
'/google-analytics-for-wordpress/google-analytics-for-wordpress.php',
'/broken-link-checker/broken-link-checker.php',
'/better-wp-security/better-wp-security.php'
);
if ( count( $unwanted_plugins ) > 0 ) :
deactivate_plugins( $unwanted_plugins );
endif;
// activate plugins
$dev_plugins = array(
'/wp-migrate-db-pro/wp-migrate-db-pro.php',
'/query-monitor/query-monitor.php'
);
if ( count( $dev_plugins ) > 0 ) :
activate_plugins( $dev_plugins );
endif;
// Transient is set for 24 hours
set_transient( 'dev-env-updated', true, ( 60 * 60 * 24 ) );
error_log( 'dev-env-updated' );
}
endif;
}
add_action( 'admin_init', 'mysite_development_environment_setup' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment