You are using the right WP function but unfortunately not passing the right parameter to make this work for you.
current_user_can()
accepts capabilities as well as roles as parameters.
In the above you are using roles and not capabilities.
You can use capabilities to make it work.
For example, if you want the minimum privilege role is author your code would look like
if ( current_user_can( 'edit_published_posts' ) ) {
//do this
}
This will allow all the roles including author to have the privilege and would stop users with roles contributor and subscriber from the access.
You can read the details of roles and capabilities from the codex here.
Related Posts:
- How to create a clone role in wordpress
- How do I make a draft post accessible to everyone?
- How do I programmatically set default role for new users?
- Create custom user role (client) that can create another custom user role (employee) of that client
- Allow roles below admin to add subscribers only
- How to force listing contributors in authors dropdown menu
- Allow authors to edit only certain users
- How do I allow a specific Role in WordPress 3+ to only see certain plugins?
- Allow editors access to added plugins
- Temporarily disable user role login and replace with message
- Change role after the user has read all the posts in a category
- Do custom user roles have any default capabilities?
- Filter available WooCommerce payment gateways by role [closed]
- How to programmatically add a user to a role?
- Can i copy administrator role to another user?
- How to change role of all users with a specific role to another role?
- I need to assign a role to visitors/guests
- How to make an author archive only for certain user role and show related CPT
- Allow users to publish child pages of the pages they have access to edit
- 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’
- How to prevent users with “edit_others_posts” capability from editing admin posts
- Access on specific pages in wordpress for a specific user
- Change the user role after x days
- Get (echo) all role names assigned to user
- Add Role inherits?
- Locking Down WordPress Application Password Permissions / Capabilities
- How can I have different groups of editors only allowed to edit certain parent+subpages?
- How to let someone preview a draft?
- WordPress missing user roles on local dev machine. Live site works fine
- Programmatically allow a non-author to edit a post based custom meta field
- Are there individual memory allocations for different user roles in WordPress?
- How to redirect specific post type with user role
- Prevent Editors from Editing/Deleting Admin Accounts
- Query users which have same dynamically generated roles as the current user
- Membership subscription, change user role when subscription runs out
- Pending status by default for a specific role
- Getting a role based on a localized role name
- How do I restrict user access to plugins?
- Change user role after bulk-import
- Show metabox for a special role
- Admin User Role Unable to See Private Posts
- Assigning certain authors to specific editors
- Custom capabilities to add, edit, remove users of a particular role only?
- Undo User Role Name Change
- add_role user capability not working
- Limit a user to have access to only specified pages?
- How can I promote a user to a network administrator?
- read_private_pages capability not working for new role
- Restrict custom post content to specific user
- List users of an array of roles
- Use PHP code to create custom user roles. Call it once?
- How can I programattically hide all admin notices for everyone except admin users
- How to exclude subscriber from the list in wordpress
- Want to know parameters that can be passed to user_can() for access control by user capabilities
- Block user roles from accessing the WordPress dashboard
- Create sub-administrator role that can do everything except use or see the code editor
- Can we hook the Customizer on a post or page on the front of the site?
- display user roles in comment form
- Is it proper to build a site supporting blog visitors in WordPress?
- Removing capabilities from cloned admin role
- User role editor – Add download files capability
- Retrieve user roles but exclude default roles
- Setting an expiration date for wordpress roles
- Could we know who published a post on WordPress?
- Auto Change WordPress Roles
- Error while creating a clone role in wordpress
- Custom Plugin – Blacklist/Whitelist domain email and change user role – Suggestions
- Change auth_cookie_expiration for specific roles and specific login times
- Infinite redirects at front end if logged in user is not an Admin (Toolset Access)
- Set user role, if an specific role created an user
- Block access to plugins.php for custom role
- Allow user to select role from front end edit profile form
- How to make WP page accessile only to specific user roles
- Remove add post for user role
- Restrict Author to post only to a specific category
- WordPress – Limit custom/specific user role to only have access to edit the contents of an Advanced Custom Fields Pro Options Page
- TCPDF only exports .pdf when user is administrator
- How to allow suscriber to access specific pages in dashboard?
- Enable plugins for a specific user role
- Switch role on submit button
- Custom User Role – can’t edit or publish pages?
- Dropdown of user roles that depend on variable
- Add role selector to custom registration page
- Multiple user role on registration
- Trying to get new role to have edit permissions for custom content type
- Why are all roles assigned to a user when using wp_insert_user()?
- Why does user_can return false for a capability during plugin deactivation?
- Removing Admin Bar Node Based on Role
- Create an email address that forwards to users in role
- How to update user role totals
- Custom user role doesn’t show up in admin
- Welcome email specific to user role
- update_user_meta on registration but only for default role type
- 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?
- Get users by rôle in a list
- Role Scoper, don’t allow other users to see pending posts
- WordPress show content if current user get spesific role and spesific meta value
- WordPress users roles wp-admin