Get the current user with wp_get_current_user()
and check if your role is in the array.
add_action( 'admin_bar_menu', 'remove_new_content_menu', PHP_INT_MAX );
function remove_new_content_menu( $wp_admin_bar ) {
// get the current user
$user = wp_get_current_user();
// define roles that cannot see the `new content` button
$blacklisted_roles = array('grocery', 'subscriber');
// remove the button if the current user has a blacklisted role
if( array_intersect($blacklisted_roles, $user->roles ) ) {
$wp_admin_bar->remove_node( 'new-content' );
}
}
Related Posts:
- How to allow suscriber to access specific pages in dashboard?
- How to redirect specific post type with user role
- How can I programattically hide all admin notices for everyone except admin users
- Block user roles from accessing the WordPress dashboard
- User role and capablities only for 1 plugin
- Block access to plugins.php for custom role
- Removing menus from users other than the administrator
- grant multiple roles access to specific admin menu item
- Custom Admin Menu Order for all User Roles
- Grant access to admin menu?
- allow editors to edit menus?
- Changing Admin Menu Labels
- How to change a user’s role?
- Is there way to rename user role name without plugin?
- How to create a clone role in wordpress
- Possible to hide Custom Post Type UI/Menu from specific User Roles?
- How to add a Capability to a User Role?
- How can I get a list of users by their role?
- How to get role of user
- How to allow editor to edit privacy page / settings only?
- How do I make a draft post accessible to everyone?
- Reset default roles and capabilities
- How do I remove dashboard access from specific user roles?
- How to fix the admin menu margin-top bug in WordPress 5.5?
- How do I programmatically set default role for new users?
- add_role() run only once?
- Show Custom Taxonomy Inside Custom Menu
- What do unfiltered_html and unfiltered_upload actually filter?
- wp_update_user not updating
- Temporary capability for current_user_can()
- alphabetically order role drop-down selection in dashboard
- Create custom user role (client) that can create another custom user role (employee) of that client
- Add “external” link to admin menu in the backend
- Change default admin page for specific role(s)
- Is it possible to add new user Roles?
- Allow roles below admin to add subscribers only
- Temporarily give ‘manage_options’ capability
- REST API, get user role?
- Is WordPress’ is_user_logged_in() secure?
- How to force listing contributors in authors dropdown menu
- Hide specific admin users’ posts
- Allow authors to edit only certain users
- How do I allow a specific Role in WordPress 3+ to only see certain plugins?
- Remove ability to access certain admin menus
- How to update role capabilities
- Allow editors access to added plugins
- Temporarily disable user role login and replace with message
- How to filter the role selector?
- Appearance->Editor not visible
- How to loop through each user id?
- Code needed to only show users own posts in a multi-user account
- How can I change a user role upon visiting a page?
- How to let the Contributor role preview unpublished posts?
- 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]
- Ordering users of a specific role by last name
- How to programmatically add a user to a role?
- Make sub menu items a main link in the admin menu using fuctions.php
- Modify custom Users Manage page
- Restrict Author to pick from media library, but not upload media
- Can i copy administrator role to another user?
- how to add custom user capabilities using add_user_meta or something else?
- Assign Subscriber capabilities to a custom user role
- How to change role of all users with a specific role to another role?
- Allow user to Publish, but not Edit or Delete
- Roles at registration (classipress)
- How to allow registered users to change their user role through frontend?
- Remove Ability for Administrators to Delete Administrators
- Order users by custom user meta
- how to change user roles for users who doesn’t have any. (about 8000 users)
- List total number of users that are authors
- Email notification for editors only
- Shold I manually add ‘cap’ to admin role ?
- Custom Post Type’s Capabilities map_meta_cap issues
- I need to assign a role to visitors/guests
- Contributors missing from author dropdown
- How to make an author archive only for certain user role and show related CPT
- Getting a user role from the user login name
- Allow users to publish child pages of the pages they have access to edit
- How do I code access to the built-in UI of a CPT when it’s placed as submenu of another CPT that is protected by role?
- Auto Delete Users (auto_delete_users)
- New Roles and Capabilities in WordPress
- WordPress Multisite Layered Admins
- Why is wp-login redirecting to the home page when I use this function?
- Is there a way to set the user Role based on email domain
- Allow contributor to view own scheduled post
- Editor and contributor roles not correct after adding function
- Adding multiple user roles dynamically
- WordPress Super Admin
- pre_get_posts Remove posts based on meta value with ‘post__not_in’
- How to add author role as a custom field to custom post type in wordpress?
- How to prevent users with “edit_others_posts” capability from editing admin posts
- How are roles stored in the database?
- Author Role – Allow editing of Gallery images
- How do I allow anyone to edit a post — but not access dashboard
- What is the difference between “create_users” and “add_users” capabilities?
- How To Remove Dashboard Menu Items for Multisite Users?
- How to delete user roles?
- Access on specific pages in wordpress for a specific user