Advertisement
mikelittle

Hide menus and plugins from users

Apr 17th, 2013
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2. /* Hide some plugins from the plugin list from everyone except user id 1 */
  3. /* Even other administrators can't see them */
  4. define( 'Z1_ADMIN_USER', 1 );
  5.  
  6. $remove_these = array(
  7.       'limit-login-attempts/limit-login-attempts.php',
  8.       'wordpress-firewall-2/wordpress-firewall-2.php',
  9.       'update-notifier/update-notifier.php',
  10.       'wp-super-cache/wp-cache.php',
  11.       'audit-trail/audit-trail.php',
  12.       'wpmudev-updates/update-notifications.php',
  13.      );
  14.  
  15. add_filter('all_plugins', 'z1_remove_some_plugins');
  16. function z1_remove_some_plugins($all) {
  17.     global $remove_these, $current_user;
  18.     if ( isset( $current_user ) && ( Z1_ADMIN_USER != $current_user->id ) ) {
  19.         foreach($all as $file => $data) {
  20.             if (in_array($file, $remove_these))
  21.                 unset($all[$file]);
  22.         }
  23.     }
  24.     return $all;
  25. } // end z1_remove_some_plugins
  26.  
  27. /* Hide some menuss from everyone except user id 1 */
  28. /* Even other administrators can't see them */
  29. $remove_menus = array(
  30.                       array( 'options-general.php', 'limit-login-attempts' ), // submenu
  31.                       array( 'options-general.php', 'update-notifier' ),
  32.                       'edit-comments.php', // top level core menu
  33.                       'wpcf7', // top level plugin menu (contact form 7)
  34.                       array( 'options-general.php', 'wpsupercache' ),
  35.                      );
  36.  
  37. add_action('admin_init', 'z1_remove_some_menus');
  38. function z1_remove_some_menus() {
  39.     global $remove_menus, $current_user;
  40.  
  41.     if ( isset( $current_user ) && ( Z1_ADMIN_USER != $current_user->id ) ) {
  42.         foreach ( $remove_menus as $m ) {
  43.             if ( is_array( $m ) ) {
  44.                 remove_submenu_page( $m[0], $m[1] );
  45.             } else {
  46.                  remove_menu_page( $m );
  47.             }
  48.         }
  49.     }
  50. } // end z1_remove_some_menus
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement