Created
February 28, 2013 14:36
-
-
Save boonebgorges/5057165 to your computer and use it in GitHub Desktop.
Hide WordPress plugins from the plugins.php admin screen in a flexible way
This file contains 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 | |
/** | |
* Prevent specific plugins from being activated (or, in some cases, deactivated). | |
* | |
* Plugins that are to be deprecated should be added to the $disabled_plugins array. | |
* | |
* Plugins that should be un-deactivatable should be added to the $undeactivatable_plugins array | |
*/ | |
function cac_hide_plugins( $plugins ) { | |
// Allow the super admin to see all plugins, by adding the URL param | |
// show_all_plugins=1 | |
if ( is_super_admin() && ! empty( $_GET['show_all_plugins'] ) ) { | |
return $plugins; | |
} | |
// The following plugins are disabled | |
$disabled_plugins = array( | |
'cforms/cforms.php', | |
'wpng-calendar/wpng-calendar.php' | |
); | |
// By default, allow all disabled plugins to appear if they are | |
// already active on the current site. This lets administrators | |
// disable them. However, if you want a given plugin to be unlisted | |
// even when enabled, add it to this array | |
$undeactivatable_plugins = array( | |
'cforms/cforms.php', | |
); | |
foreach ( $disabled_plugins as $disabled_plugin ) { | |
if ( array_key_exists( $disabled_plugin, $plugins ) && | |
( in_array( $disabled_plugin, $undeactivatable_plugins ) || ! is_plugin_active( $disabled_plugin ) ) | |
) { | |
unset( $plugins[ $disabled_plugin ] ); | |
} | |
} | |
return $plugins; | |
} | |
add_filter( 'all_plugins', 'cac_hide_plugins' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment