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 can I hide a category from Contributors in the edit/add new post screen?
- REST API, get user role?
- Restrict users on multisite WordPress install
- Basic auth WordPress REST API dilemma
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- Author Role – Allow editing of Gallery images
- Can I create users that have access to *some* other users posts instead of all other users posts?
- How to remove sticky post capability for a specific user role?
- How to Add Author Editing Capability to Existing Post by Admin
- Custom post type capabilities require “create_posts” to access the edit posts list page
- User registration approval based on role selected
- add_menu_page() for more than one user role
- How do I turn off the Admin Bar for all Subscribers?
- Hide from specific role the top admin bar new button
- exclude roles from overview
- Plugin to restrict access to pages in wp-admin
- How to allow user to edit post in wordpress
- Dangers to allowing Access-Control-Allow-Origin: * for Feeds only?
- Display user meta by different user role
- Conditional tag based on the role of author in author.php
- allow non logged in user to upload images in media library
- Assign a role to the user who registers on a form
- DISALLOW_FILE_EDIT constant being ignored
- Create custom post with custom user rules
- How to change user role using hook
- Reset Roles (or undo role changes on theme change)
- User roles are changing automatically
- Custom Roles for access to specific term(s)
- Give Editor Access to Custom Theme Options
- Custom Capabilities for CPT and Problem with current_user_can()
- Which capabilities are available in Gravity Forms Salesforce plugin? [closed]
- ‘upload_mimes’ filter seems to be restricting viewing/downloading as well
- Allow user edit widgets
- Problems using ‘add_role’
- Let editors view post in admin but not be able to perform a save/edit
- Capabilities don’t add
- Show menu in sidebar if on specific page AND specific user role (is_page, current_user_can)
- Conditional Tag for Wishlist membership. If the user is added to two levels show particular content
- Assigning a capability to a user role (code check)
- Adding a role using Members and Formidable Forms [closed]
- Adding all custom capabilities to admin
- How to give plugin access to specific role(s)
- current_user_can( ‘edit_user’ ) does not work
- Restrict Users to Only Edit Media Owned by Users in Their Role
- Remove plugin settings from post creation page for a user role
- Change role in maintenance mode
- How to make this custom capability work? [duplicate]
- underscore not allowed in role slug?
- Give a user role capability to create orders for clients
- Restrict content piece by role – Protection message in content?
- Custom Admin Menu Order for all User Roles
- WordPress install checking permissions of user id 0
- Force “submit for review” on update?
- Allow users to change author of post
- Access to option page by role/capability
- Custom User Role
- Is there a way for a limited user to just view the page of a post without being able to edit it?
- How do I make a draft post accessible to everyone?
- Authors Ability to Review Post from Contributors
- Control Category of each user can post
- Get users by rôle in a list
- WordPress show content if current user get spesific role and spesific meta value
- WordPress users roles wp-admin
- User has empty instead of custom role when logged in