Skip to content

Instantly share code, notes, and snippets.

@rniswonger rniswonger/functions.php
Last active Aug 8, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.