Skip to content

Instantly share code, notes, and snippets.

@davemac
Created October 26, 2012 05:37
Show Gist options
  • Save davemac/3957052 to your computer and use it in GitHub Desktop.
Save davemac/3957052 to your computer and use it in GitHub Desktop.
Hide plugins from certain WP users
function filter_visible_plugins($plugins) {
//Plugin file paths relative to /wp-content/plugins/
$pluginsToHide = array(
'akismet/akismet.php',
'hidden-plugin/hidden-plugin.php',
'another-plugin/filename.php',
);
//As an example, lets hide the above plugins from everyone
//except user 'smith'. Replace this with your own security checks.
$currentUser = wp_get_current_user();
$shouldHide = $currentUser->get('user_login') != 'smith';
if ( $shouldHide ) {
foreach($pluginsToHide as $pluginFile) {
unset($plugins[$pluginFile]);
}
}
return $plugins;
}
add_filter('all_plugins', 'filter_visible_plugins');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment