If you only need this for current user current_user_can()
accepts both roles and capabilities.
UPDATE: Passing a role name to current_user_can()
is no longer guaranteed to work correctly (see #22624). Instead, you may wish to check user role:
$user = wp_get_current_user();
if ( in_array( 'author', (array) $user->roles ) ) {
//The user has the "author" role
}
Related Posts:
- How to check if a user is in a specific role?
- Check if user is admin by user ID
- create users to site with specific language
- Users Unable to Access Dashboard/Posts/Pages
- Logout USER form backoffice after 30 minutes of inactivity [closed]
- Newly created user role not displaying on users screen
- 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
- How to restrict dashboard access to Admins only?
- Admin Page Redirect
- How to prevent access to wp-admin for certain user roles?
- How to display the user that published a pending post?
- Custom user role that can only edit specific (non-custom-type) page and all child pages [duplicate]
- Only allow administrators and editors to access wp-admin
- Add a button to users.php
- Prevent from deleting any user role but subscriber
- What is the capability that permits access to WP-Admin?
- Display sortable User meta column in admin panel user’s page
- Displaying which Role the current user is assigned to
- How to display multiple custom columns in the wp-admin users.php?
- Hooking into register_admin_color_schemes
- How to hide a specific user role option in a user role list?
- Adding HTML/Text to Top of Subscriber’s Profile Backend Page
- Removing user fields [duplicate]
- Custom role based users are not able to access wp-admin
- wp-admin edit user url wont show up correct url [closed]
- Custom roles showing HTML entities in title form field
- Only allow administrators and editors to access wp-admin
- Stop loading “collaborators” users on add new post or page?
- Distinguish profile user and admin user IDs / get ID of user being edited
- Uncheck the box “Send User Notification” by default on new-user.php
- Detecting all admins that are logged in
- Subscribers become Authors after Upgrade? / Mass Update of Users?
- Stopping user deletion from running on error
- Allow administrators to pick post author on custom post type edit screen
- Filter dropdown in users.php “delete user” bulk edit screen
- Add count for new registered user in Users tab
- Adding Custom Capabilites
- Restrict Author role to only 3 wp-admin pages
- Users disappeared from wp-admin
- Why is unfiltered_upload not working despite being enabled?
- WP admin user search doesn’t return all users
- Hide username discovery
- How to get Role Subscribe Users on Admin Menu only in Pages in WordPress
- Downgrade admin account by mistake
- How to set where user is redirected to after logging in at wp-login?
- I accidentally deleted an admin user and all their content is now gone from the site. [closed]
- Restrict submitters from wp-admin [duplicate]
- Nickname field isn’t appearing in Admin
- How to allow WordPress updates to only one specific administrator?
- User Capabilities are not available in WP REST permission callback?
- Is there a filter to edit html of user-edit.php
- Change users.php WP_User_Query
- Create new user from phpMyAdmin
- How do I make it so that the all users page is not a white screen?
- User Roles: How to hide a plugin from showing in WP-Admin?
- Is WordPress secure enough for a multi-user article directory?
- define two login page url
- On Users (user.php) in wp-admin disable/hide “Bulk Actions” and “Change Role To”
- Login issue with subdomain installs
- Hook into form handle from admin users table
- Give wp-admin access for shop managers
- restrict admin panel sections to users
- CSRF attack to create USER
- adding existing menu page on new customer user role
- How to keep the plugin submenu open on viewing a custom version of users.php?
- Cannot login in WordPress even after changing hash password in phpmyadmin
- WordPress User profile page fields missing
- Anyone Can Register
- 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 Wp backend area on the users.php page to allow for searching by email domain and role from the “users search” input box
- WordPress Users page missing user count next to different types of users
- How to create a User Role and give permission to only use Web Stories plugin?
- Searching for a custom meta from user.php in the admin
- how to Hide all products except the General Manager role in the WordPress admin panel?
- How to enable a site administrator to edit users in a WordPress network/ multisite setup?
- How to use Yoast SEO backend in english even if WPLANG variable is not english?
- Admin first hook that outputs HTML?
- How do I list in the backend all users that were assigned to a custom role?
- To remove default dashboard items and add quick draft widget for custom post type
- How do I host WordPress on a hidden domain through a reverse proxy?
- Custom Fields – Taller editing area
- WordPress (behind HAProxy and Jetty), not multisite, in sub folder – and /en/wp-admin/ keeps redirecting to /wp-admin/
- List all private pages user has access rights to read
- What are the requirements to make the admin toolbar show up on the front end
- Sorry, you are not allowed to access this page
- Is possible to allow user to login with different role?
- Custom Admin Pagination links
- Have different site location for wp-admin in IIS
- Lost administrator privileges and can’t find a fix
- Cannot redeclare wp_update_core()
- How can I change my assigned user role in WordPress 3.5.1?
- WordPress /wp-admin redirect to wrong port in docker
- fine-grained capabilities for user related capabilities
- Strange Popup Ad on my WordPress Admin Dashboard
- Custom User Role: Can Edit Own Page, Cannot Create New
- Get Post ID in Admin Edit screen otherwise generate it?
- I want to know if it’s good for SEO [closed]
- Redirect users based on their roles, is_admin()
- insert an admin table inside another admin page
- /wp-admin/ – this link showing me “Index of /wp-admin”/ instead of dashboard