Custom admin panel based on user roles
-
I solved my own problem which might be useful for others. Building on hacks like this (10-wordpress-dashboard-hacks) I needed to customize the admin panel. However, I needed to be able to have different admin panels based on user roles (without using any deprecated code). Here is my solution!
I added this to my functions.php in my theme:
// Want to pare down your admin panel for authors? // Using these functions we make this possible! //this customization is basically for authors //START CUSTOM ADMIN PANEL CODE: //First we remove some widgets function adminpanel_based_on_role() { if (current_user_can('publish_posts') && !current_user_can('install_plugins')){ global$wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } } add_action( 'wp_dashboard_setup', 'adminpanel_based_on_role' ); //Next we remove menu items function remove_menu_items() { if (current_user_can('publish_posts') && !current_user_can('install_plugins')){ global $menu; $restricted = array(__('Links'), __('Comments'), __('Media'), __('Plugins'), __('Tools'), __('Users')); end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){ unset($menu[key($menu)]);} } } } add_action('admin_menu', 'remove_menu_items'); //END CUSTOM ADMIN PANEL CODE
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom admin panel based on user roles’ is closed to new replies.