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 do I force a single column layout in screen layout
- Sortable admin columns, when data isn’t coming from post_meta
- wp_list_table search box does not show
- How to remove the site health dashboard widget?
- Can I rename the wp-admin folder?
- What’s the purpose of admin canonical tag?
- Copy my user account’s wp-admin dashboard layout to other users?
- How to display multiple custom columns in the wp-admin users.php?
- WordPress custom permalinks not working on OS X localhost
- How to Remove Checkbox for Excerpt Under Screen Options
- pre_get_posts Remove posts based on meta value with ‘post__not_in’
- Remove order field from Page Attributes box
- Restrict dashboard access for specific user roles to specific actions
- Disable the administration email address verification (new in 5.3)
- https://mydomain/wp-admin redirects to wp-login.php?redirect_to=https%3A%2F%2Fmydomain%2Fwp-admin%2F&reauth=1
- How to redirect specific post type with user role
- Get which template being in use within WordPress-admin
- /wp-admin/ works but website doesn’t load
- Add column to pages table
- My email address is displaying an email which does not work. What do i do?
- Removing Dashboard Menu Items Through The Database
- Is there any way to make myself an admin?
- Can log as admin but dashboard missing [closed]
- WordPress Login redirection according to user role
- Customising Word press Admin – Add Post Page functionality to another similar page
- How to allow WordPress updates to only one specific administrator?
- How can I remove commas when adding tags?
- Displaying Title in Title Tag on Edit page?
- Cannot change Connection Information in admin interface
- How can I remove unwanted word on my WP site?
- WordPress blog clone.. wp-admin issue
- How to take the help button and link off the dashboard
- How do I fix wp-admin error when exporting reusable blocks?
- issue with wordpress [wp-admin] redirects, when using kubernetes ingress hosting two wordpress websites using path
- Can’t acces login on new site
- Infinite redirects at front end if logged in user is not an Admin (Toolset Access)
- WordPress Admin Panel Left Sidebar No showing on Post create page
- wp-config.php not affecting my site
- How to prevent spams from admin-ajax.php file?
- Custom user roles are unable to login
- After changing Site http to https, can’t access wp login page with a digitalocean hosting
- Strange wp-admin problem for all users/adminstrators except the original one?
- stop customize.php redirect to login page if admin is not logged in
- How can I remove “Add new” button on custom post type
- Organising and display thousands of photos in media library
- Checkbox not showing as checked on UserProfile (even with checked=”checked”)
- Get URL of current featured image with JS in edit post view
- Block tools menu in wp-admin?
- WordPress Admin: open popup window on a custom button
- Cannot Access wp-admin