You’re correct in that you should be checking for a capability. However, manage options is only given to administrators by default. You should check against a capability that both editors and administrators have such as delete_others_posts.
function restrict_admin(){
//if not administrator, kill WordPress execution and provide a message
if ( ! current_user_can( 'delete_others_posts' ) ) {
wp_die( __('You are not allowed to access this part of the site') );
}
}
add_action( 'admin_init', 'restrict_admin', 1 );
See roles and capabilities from the codex.
Related Posts:
- Only allow administrators and editors to access wp-admin
- Restrict Author role to only 3 wp-admin pages
- Is WordPress secure enough for a multi-user article directory?
- How to check if a user is in a specific role?
- How to prevent access to wp-admin for certain user roles?
- Check if user is admin by user ID
- Restrict admin access to certain pages for certain users
- create users to site with specific language
- Prevent from deleting any user role but subscriber
- What is the capability that permits access to WP-Admin?
- Moving wordpress from localhost to server throws admin panel access error?
- Displaying which Role the current user is assigned to
- How to hide a specific user role option in a user role list?
- Adding HTML/Text to Top of Subscriber’s Profile Backend Page
- Custom role based users are not able to access wp-admin
- How to inhibit dashboard and profile management access to normal users?
- Custom roles showing HTML entities in title form field
- Users Unable to Access Dashboard/Posts/Pages
- Can’t access WordPress as an admin – but I can log in as a user!
- Redirect non-admin users away from wp-admin/index.php (main dashboard page) to wp-admin/profile.php
- Allow administrators to pick post author on custom post type edit screen
- admin_post action not usable if admin access denied to user
- Adding Custom Capabilites
- Why is unfiltered_upload not working despite being enabled?
- Logout USER form backoffice after 30 minutes of inactivity [closed]
- I can´t access my admin panel. I tried all possible solutions
- Lost administrator privileges and can’t find a fix
- Downgrade admin account by mistake
- How to set where user is redirected to after logging in at wp-login?
- How to remove dashboard access (wp-admin) for author but not disable the capabilities?
- Deploying WordPress for clients – what do they have access to?
- How to Find The Email of a WP Admin Account
- User Capabilities are not available in WP REST permission callback?
- Change users.php WP_User_Query
- User Roles: How to hide a plugin from showing in WP-Admin?
- define two login page url
- Newly created user role not displaying on users screen
- Admin Page access
- How to check if a user is in a specific role?
- Not able to access WP Admin, it says “Sorry, you are not allowed to access this page.”
- How to logout the current user without notices and warnings?
- Give wp-admin access for shop managers
- restrict admin panel sections to users
- adding existing menu page on new customer user role
- Localhost install: Administrator lost administrator access; cannot access Dashboard
- WordPress blog fails to open
- Is it possible to tell if a user is logged into WordPress from looking at the cookies which are set?
- Extend user search in the users.php page to allow for searching by role and excluding specified email domains from the “users search” input box
- After Upgrade: $user becomes unknown (id: 0) after successful login?
- how to Hide all products except the General Manager role in the WordPress admin panel?
- How to remove screen options and help links in the admin area?
- wp_list_tables bulk actions
- How do I find all admin users using phpmyadmin?
- Hide username from users list
- Activating Child Theme Breaks Website, Blank Page, Error 500
- Create Read Only Admin
- wp-admin is redirecting to back to home page (localhost)
- Rename W3 Total Cache admin menu
- Cloned a site but can’t log in – redirecting to old site
- Can I edit the wp_post > post_content right before its inserted/updated?
- How to check if upload window came from the featured image link?
- Managing Users and Creating Groups [closed]
- Can’t log into wp-admin after migration from localhost to server
- Add menu option to “New Post” menu in admin bar
- Assigning certain authors to specific editors
- Linking table cells to network folders
- Remove bulk option row
- Admin menu in front-end
- Require Login Redirect to Login Page
- Filtering the Admin Comments List to Show Only Comments from the Current User?
- How to fix ob_end_flush() failed to send buffer of zlib output compression (1)?
- Delete the “wp-admin” folder – what could go wrong?
- Nickname field isn’t appearing in Admin
- Creating custom admin panel pages without making a plugin?
- Blank page when viewing wp-admin
- Is it possible to display my theme sidebar in wordpress admin?
- wp-admin: “Sorry, you are not allowed to access this page.”
- How to access wordpress from domainB which is installed at domainA
- How to optimize the opening speed of admin panel?
- How to change the URL of sub menu page?
- Change wordpress admin home page
- Strange wp admin edit buttons issue
- Cannot access wp-admin after migration to another place
- Regular users logs in as ADMIN if Admin logged in recently
- Enable Excerpt field inside the post editor for pages
- Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- Not able to access WP admin Page, redirected and a drop down login menu appears 401 error
- OSX El Capitan local install Maximum upload file size: 2 MB But php.ini set to 64M
- Is it possible to outsource wp-admin to another server?
- Wp mwnu not works at all
- Can’t log into WordPress after domain change
- Search box for hierarchical taxonomies in admin interface
- Custom Admin Message from external source to multiple users
- How can visitors redirect wp-admin to the homepage?
- You do not have permission to access this document on form submit
- Redirecting the user to the admin table area after publishing a post, getting an invalid response error?
- How can you change the admin dashboard URL without symlinking?
- Display posts with id equal to relationship value
- How to create a User Role and give permission to only use Web Stories plugin?
- Degraded WordPress admin dashboard performance [closed]