Posted By

tomdowning on 11/20/12


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

qing606


Wordpress hide admin menus + submenus


 / Published in: PHP
 

use for clients to hide tabs + buttons in admin

  1. add_action( 'admin_menu', 'my_remove_meta_boxes' );
  2. add_action('admin_menu', 'remove_the_dashboard');
  3.  
  4. function my_remove_meta_boxes() {
  5. if(get_current_user_id()!=1):
  6.  
  7. remove_menu_page('edit.php');
  8. remove_menu_page('link-manager.php');
  9. remove_menu_page('edit-comments.php');
  10. remove_menu_page('edit.php?post_type=client' );
  11. remove_menu_page('themes.php');
  12. remove_menu_page('plugins.php');
  13. remove_menu_page('tools.php');
  14. remove_menu_page('w3tc_general');
  15. add_action( 'media_buttons_context' , create_function('', 'return;') );
  16.  
  17. remove_submenu_page('options-general.php', 'options-discussion.php');
  18. remove_submenu_page('options-general.php', 'options-writing.php');
  19. remove_submenu_page('options-general.php', 'options-reading.php');
  20. remove_submenu_page('options-general.php', 'options-media.php');
  21. remove_submenu_page('options-general.php', 'options-privacy.php');
  22. remove_submenu_page('options-general.php', 'options-permalink.php');
  23. remove_submenu_page('options-general.php', 'tinymce-advanced');
  24.  
  25. remove_meta_box('postexcerpt', 'page', 'normal');
  26. remove_meta_box('trackbacksdiv', 'page', 'normal');
  27. remove_meta_box('commentstatusdiv', 'page', 'normal');
  28. remove_meta_box('commentstatusdiv', 'page', 'normal');
  29. remove_meta_box('commentsdiv', 'page', 'normal');
  30. remove_meta_box('revisionsdiv', 'page', 'normal');
  31. remove_meta_box('authordiv', 'page', 'normal');
  32. remove_meta_box('sqpt-meta-tags', 'page', 'normal');
  33. remove_meta_box('tagsdiv-post_tag','page', 'normal');
  34. remove_meta_box('categorydiv','page', 'normal');
  35. remove_meta_box('pageparentdiv','page', 'normal');
  36. remove_meta_box('postimagediv','page', 'normal');
  37.  
  38. endif;
  39. }
  40.  
  41. function remove_the_dashboard () {
  42. global $menu, $submenu, $user_ID;
  43. $the_user = new WP_User($user_ID);
  44. reset($menu); $page = key($menu);
  45. while ((__('Dashboard') != $menu[$page][0]) && next($menu))
  46. $page = key($menu);
  47. if (__('Dashboard') == $menu[$page][0]) unset($menu[$page]);
  48. reset($menu); $page = key($menu);
  49. while (!$the_user->has_cap($menu[$page][1]) && next($menu))
  50. $page = key($menu);
  51. if (preg_match('#wp-admin/?(index.php)?$#',$_SERVER['REQUEST_URI']) && ('index.php' != $menu[$page][2]))
  52. wp_redirect(get_option('siteurl') . '/wp-admin/edit.php?post_type=page');
  53. }

Report this snippet  

You need to login to post a comment.