Created
October 26, 2012 05:37
-
-
Save davemac/3957052 to your computer and use it in GitHub Desktop.
Hide plugins from certain WP users
This file contains hidden or 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
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