I believe the correct solution here is to just update the $capability component of the admin_menu items rather than just remove them from the menu structure.
Try this:
/** Set 'administrator' cap for particular menu items **/
function update_admin_menu() {
global $menu, $submenu;
$menu[10][1] = 'administrator'; // Media
foreach( $submenu['upload.php'] as &$item ) {
$item[1] = 'administrator';
}
$menu[75][1] = 'administrator'; // Tools
foreach( $submenu['tools.php'] as &$item ) {
$item[1] = 'administrator';
}
}
add_action( 'admin_menu', 'update_admin_menu', 1000 );
Please note that checking against user levels is deprecated, but it works in this situation and is essentially the same as it would be if you created a new cap (which administrators would automatically have access to,) and assigning that capability to these menu items instead.
Related Posts:
- How to make WP page accessile only to specific user roles
- wp_update_user not updating
- Is WordPress’ is_user_logged_in() secure?
- Temporarily disable user role login and replace with message
- how to add custom user capabilities using add_user_meta or something else?
- Is there a way to set the user Role based on email domain
- pre_get_posts Remove posts based on meta value with ‘post__not_in’
- What is the difference between “create_users” and “add_users” capabilities?
- Access on specific pages in wordpress for a specific user
- How to ‘unpublish’ or ‘hide’ posts when user role changes?
- Restricting access to content
- Hide Specific User Page
- Let new user role to ‘edit_others_posts’ of other user role, not of its own type
- How can I have different groups of editors only allowed to edit certain parent+subpages?
- How do I remove the Other Roles field (from User Role Editor plugin) in wp-admin/user-new.php
- How to redirect specific post type with user role
- wordpress editor role remove all but ‘menus’ in appearance menu
- Parent User and Child User – relate users
- How to create user specific pages (not user role!)?
- Assigning certain authors to specific editors
- Limit a user to have access to only specified pages?
- Plugin creation – how to add user rights?
- User restricted only show posts assigned to current user
- Restrict custom post content to specific user
- Hide front-end from every logged out user and redirect them to the default login page
- How to restrict an admin page, if the user is not superadmin?
- Need to block user role from accessing bbPress all together
- How to create a front facing user sign up, log in and profile pages like FoodGawker.Com [closed]
- Is WordPress secure enough for a multi-user article directory?
- Infinite redirects at front end if logged in user is not an Admin (Toolset Access)
- Is there a way to allow users with “Subscriber” user role to access media library in backend and frontend
- grant multiple roles access to specific admin menu item
- Check what capabilitie(s) an action requires
- Is it possible to restrict a specific user to edit a specific custom post.
- New folder and file permissions are not correct
- How to change user role setting in members plugin so that user can only edit his own post?
- How to change a user’s role?
- Allow member to have access to custom post type only. Permission to only edit their own posts
- Is it possible to add new user Roles?
- Troubleshooting a “You do not have sufficient permissions to access this page” error
- Restrict admin access to certain pages for certain users
- Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
- Temporarily give ‘manage_options’ capability
- Only allow administrators and editors to access wp-admin
- Hide specific admin users’ posts
- Add Capabilities to Custom Post Type after it has been created [duplicate]
- How to allow registered users to change their user role through frontend?
- if role is logged in then do something
- Shold I manually add ‘cap’ to admin role ?
- Getting a user role from the user login name
- Why is wp-login redirecting to the home page when I use this function?
- Allow contributor to view own scheduled post
- Editor and contributor roles not correct after adding function
- How are roles stored in the database?
- How to delete user roles?
- Capability for allowing user to post own comments without moderation
- I am adding a new class to my body tag if the logged in user is subscriber, need help
- How to Orderby User Role?
- Prevent custom user role to add new pages
- The delete_posts capability?
- Capabilites not working [closed]
- get approved users only ( ultimate member plugin )
- Create Super Admin that cant be deleted
- remove/hide pages from users backend
- Assign second role to user
- Adding Capabilities to a WordPress User Account
- New user is assigned 2 roles: customer and superadmin
- bbPress plugin moderator roles
- how to set any post creation for pending status and let the admin approve it first?
- Allowing user to edit posts based on the post status
- Allow user role “salesman” to view only “client” role users
- Purpose of Adding Capability to Role But Not Grant?
- bbPress: How to set conditional for specific user -or- user role, to be displayed in user profile
- Menu page with list of users
- How to check user role?
- reset the users roles – is there a way to do this?
- Custom wordpress admin page/url “You do not have sufficient permissions to access this page.”
- user_can() not working for comment authors
- WordPress add_rewrite_rule redirection match GET variable not passing through to custom template
- Redirect admin 403 “Cheatin uh?” admin pages
- Letting users create a post that is a custom post type from a page
- User generated content and security
- Learndash change user role after completing the course
- How to disable activation email to specific user role?
- logout users with specific role after close browser tab
- Admin user name not showing up in author dropdown
- Separate user bases or hide users of another role or connected to another minisite
- How to restrict subscriber editing other posts but read specific posts in backend
- Publishing post strips custom html element when user is not admin
- Best practices to handle multilpe roles and capabilities?
- Allow multiple roles to specific user
- How do I restrict a second admin certain access?
- user has permission to read a custom post but it is not being shown in wordpress plugin
- Restrict custom fields based on user roles
- Select dropdown with 2 choices from foreach
- translate_user_role doesn’t work
- How to assign role to a custom registration form?
- How to add user roles? [closed]
- Check if specific role exists
- Role Scoper, don’t allow other users to see pending posts