I figured it out in the end and this is the code I used:
function restrict_menus() {
$author = wp_get_current_user();
if( isset( $author->roles[0] ) ) {
$current_role = $author->roles[0];
} else {
$current_role="no_role";
}
if( 'contributor' == $current_role ) {
$screen = get_current_screen();
$base = $screen->id;
if( 'edit-post' == $base || 'upload' == $base || 'tools' == $base || 'edit-comments' == $base ) {
wp_die( 'Cheatin’ uh?' );
}
}
}
add_action( 'current_screen', 'restrict_menus' );
Related Posts:
- WordPress Remove Submenus
- Add a Separator to the Admin Menu?
- Adding a custom admin page
- How to remove entire admin menu?
- How do I remove dashboard access from specific user roles?
- Plugin to remove Admin menu items based on user role?
- Add my own button next to “Screen options” and “Help” in the admin
- Prevent author from changing their posts if admin has modified
- Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
- How to remove administrator role in settings -> general -> New User Default Role?
- Create un-removeable user
- How to show custom menu items in the WordPress android app?
- Custom CSS In Admin Only For Certain Roles
- Remove admin AND editor from the “change role to” menu in user listing
- Appearance->Editor not visible
- Custom WP_List_Table displays blank rows
- How do I set up a webhook?
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- Customize the upload screen
- Admin pages have no content
- WordPress Left Hand Side Admin Menu Always Collapsed
- Blocking Administrative Access to Authors and Subcribers?
- Customize Admin Users Screen based on Role
- Make certain pages uneditable by editors?
- Reorder plugin items in the admin menu
- Re-ordering Admin Submenu Sections
- Reference external file as a function
- Add number new posts (post_status = pending) to administration menu [duplicate]
- add_submenu_page set for multiple roles [duplicate]
- Restrict dashboard access for specific user roles to specific actions
- How To Create User Specific Admin User Pages?
- Change the Default Pages Menu View in wp-admin
- How can I restore admin capabilities?
- How to change admin menu position of “Media”?
- Change top level menu item to point to custom submenu item
- Associating custom submenu item with post type of top level menu item
- What determines whether admin toolbar is shown to a logged-in user?
- Admin doesn’t have sufficient permissions to plugin’s page
- Remove Admin sidebar link
- Single category’s posts list in admin menu
- How do you set up a WordPress blog with multiple authors to allow something like StackExchange’s “community wiki” feature?
- Dashboard menu missing
- page not updating with database
- Why am I timing out when using the Menu Editor?
- 500 internal server error on wp-admin only
- Only Admin can Edit, Delete or Update
- add_cap for editor but no admin role
- How can I POST or GET to the same admin page from which I am POST-ing or GET-ing
- Shared account / dual blogging in WordPress
- Output the admin menu_position for each item
- Bind custom role to admin page
- avoiding the display of certain categories to certain user roles at content entry time
- remove menus for a specific role?
- How can I add a menu item to the admin area?
- Backend Checkboxes working – but not visual?
- WordPress Admin Menu Order for ‘admin.php’ pages
- current_user_can(‘administrator’) not working in custom login
- Show global Message in User Profiles with admin only Input field in WordPress Backend
- How to make sure your admin doesn’t hi-jack you site?
- Redirect admin 403 “Cheatin uh?” admin pages
- Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
- How should I setup the “Users” area to hand over to a client?
- solution to prevent specific admins from altering site contents
- Admin user roles/permissions
- Posts in sidebar only by admin
- Give admin_menu permission to specific users
- Show all admin menus in a table
- Highlight active Admin Menu when added though add_menu_page
- require/include php file in add_menu()
- Create WordPress Menu Item Without Linking to a Custom Page
- Redirect non-admin after login, and in url – /admin
- Hide top admin panel for non admin and non editors
- How can I create multiple different admin roles with their own capabilities
- Different role for free and pro users in wordpress without using bbpress
- Simple CSS admin pagination
- How to change the default url for ‘Posts’ link?
- Unsure how to add simple checkboxes that write to a small table to admin
- Add a link to the Admin menu
- Reference external file as a function
- Different customer login form than administrator login form?
- Display admin sidebar into custom post pages if logged
- Custom WP_List_Table displays blank rows
- What are the standard admin CSS id/class tags?
- How to remove admin menu pages inserted by plugins?
- Admin Ajax is returning 0
- Add custom column to Users admin panel
- wp_verify_nonce vs check_admin_referer
- How to determine whether we are in add New page/post/CPT or in edit page/post/CPT in wordpress admin?
- how to know if admin is in edit page or post [duplicate]
- Modal window from within WordPress admin
- Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?
- Where in WP can I check history or log of updates of plugins etc?
- How does admin-ajax.php work?
- Remove update nags for non-admins [duplicate]
- Give Editor Access To Sidebar
- How can I speed up my WP admin section?
- How to pass parameters to admin_notices?
- Admin: very slow edit page caused by core meta query
- if admin is logged in
- How to Add a Third Level Sub Menu to the WordPress Admin Menu