Skip to content

Instantly share code, notes, and snippets.

@boonebgorges
Created February 28, 2013 14:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boonebgorges/5057165 to your computer and use it in GitHub Desktop.
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
<?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