Skip to content

Instantly share code, notes, and snippets.

@trishasalas
Forked from trepmal/dev-plugins.php
Created June 7, 2017 10:12
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 trishasalas/64116aed5d91469d082186e1456aea48 to your computer and use it in GitHub Desktop.
Save trishasalas/64116aed5d91469d082186e1456aea48 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Dev Plugins
*/
add_action( 'muplugins_loaded', function() {
// Plugins to activate automatically.
$auto_activate = [
'debug-bar/debug-bar.php',
'debug-bar-extender/debug-bar-extender.php',
'debug-bar-console/debug-bar-console.php',
'mail-test/mail-test.php',
'rewrite-rules-inspector/rewrite-rules-inspector.php',
'abkjfdkkj/abkjfdkkj.php',
];
// Remove entries that don't exist to avoid activation warnings.
foreach ( $auto_activate as $k => $slug ) {
if ( ! file_exists( WP_PLUGIN_DIR . "/$slug" ) ) {
unset( $auto_activate[ $k ] );
}
}
// Force activation.
add_filter( 'option_active_plugins', function ( $option ) use ( $auto_activate ) {
return array_merge( $option, $auto_activate );
});
// Remove from UI.
add_filter( 'all_plugins', function ( $all_plugins ) use ( $auto_activate ) {
foreach ( $auto_activate as $k ) {
if ( isset( $all_plugins[ $k ] ) ) {
unset( $all_plugins[ $k ] );
}
}
return $all_plugins;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment