You can use wp_get_current_user() function to get current logged in user’s role
//Remove admin menu items if not admin
function remove_admin_bar_links() {
global $wp_admin_bar, $current_user;
$user = wp_get_current_user();
if ( in_array( 'author', (array) $user->roles ) ) {
$wp_admin_bar->remove_menu('updates'); // Remove the updates link
$wp_admin_bar->remove_menu('comments'); // Remove the comments link
$wp_admin_bar->remove_menu('new-content'); // Remove the content link
$wp_admin_bar->remove_menu('wp-logo'); // Remove the WP Logo link
$wp_admin_bar->remove_menu('wpseo-menu'); // Remove the Yoast SEO menu
}
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
Related Posts:
- Custom Roles for access to specific term(s)
- Allow member to have access to custom post type only. Permission to only edit their own posts
- How to restrict attachment download to a specific user?
- wp_update_user not updating
- Allowing users to edit only their page and nobody else’s
- Troubleshooting a “You do not have sufficient permissions to access this page” error
- Restrict admin access to certain pages for certain users
- How can I hide a category from Contributors in the edit/add new post screen?
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- How to assign specific users the capability to edit specific pages / posts / custom post types
- Hide Admin Menu for Specific User ID who has administrator Role
- Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
- Is WordPress’ is_user_logged_in() secure?
- Only allow administrators and editors to access wp-admin
- Restrict users on multisite WordPress install
- Using JWT to authenticate a user with an external system?
- Allow anonymous user to access Themes Customizer
- Temporarily disable user role login and replace with message
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- if role is logged in then do something
- What is the difference between “create_users” and “add_users” capabilities?
- How to add another user to this remove_menu function?
- How can I change plugin to give access to editor user role?
- How to set privilege to wordpress subscriber for private page
- Capability for allowing user to post own comments without moderation
- Can I create users that have access to *some* other users posts instead of all other users posts?
- Set default page for user account in admin
- Restricting access to content
- Hide Specific User Page
- Let new user role to ‘edit_others_posts’ of other user role, not of its own type
- How can I have different groups of editors only allowed to edit certain parent+subpages?
- How to Add Author Editing Capability to Existing Post by Admin
- Custom post type capabilities require “create_posts” to access the edit posts list page
- Only allow administrators and editors to access wp-admin
- Hide everything on site for visitors except specific page IDs
- How do I remove the Other Roles field (from User Role Editor plugin) in wp-admin/user-new.php
- Plugin to restrict access to pages in wp-admin
- Restrict post to user_id
- add_option_page capability behaving strange
- Access denied on Published Pages but not on WordPress /wp-admin/
- access the plugins for each role in WordPress multisite
- wordpress editor role remove all but ‘menus’ in appearance menu
- How to disable a specific page for a specific user
- remove/hide pages from users backend
- Restrict Author role to only 3 wp-admin pages
- Parent User and Child User – relate users
- How to restrict logged user to view only certain pages?
- How to create user specific pages (not user role!)?
- Create custom post with custom user rules
- Why does get_posts only show results for Admins or logged-out users?
- Conditional menu for registerd users/guests (Genesis framework)
- How can I create an upload page for (and only visible to) specific users?
- Restrict Access in Admin Panel
- Create a User Role with permissions to only upload files to the media library?
- Plugin creation – how to add user rights?
- User restricted only show posts assigned to current user
- ‘post’ only for editor and administrator
- Why: sticky front page code, shows latest non-sticky on logged-in front page
- WordPress Login redirection according to user role
- Disable all admin UI access to authors (except to custom post type add, edit and modify)
- Hide all pages except landing page
- Hide front-end from every logged out user and redirect them to the default login page
- Allow admins to login as other users
- How to restrict an admin page, if the user is not superadmin?
- How can I change access permissions across many pages?
- Redirect admin 403 “Cheatin uh?” admin pages
- How to create a front facing user sign up, log in and profile pages like FoodGawker.Com [closed]
- Profiles site with access levels
- User access control in sidebar archive and categorires
- Is WordPress secure enough for a multi-user article directory?
- Give users acces to admin a single post or set up WP network?
- if role is logged in then do something
- Infinite redirects at front end if logged in user is not an Admin (Toolset Access)
- Specify the level of access to different pages at the time of user creation
- Is there a way to allow users with “Subscriber” user role to access media library in backend and frontend
- Restrict Users to Only Edit Media Owned by Users in Their Role
- Remove plugin settings from post creation page for a user role
- Custom user roles are unable to login
- grant multiple roles access to specific admin menu item
- When add analytics script, wordpress user login not working
- How to make this custom capability work? [duplicate]
- Hide WordPress “wp-admin” dashboard to User IDS
- Check what capabilitie(s) an action requires
- How do I restrict a second admin certain access?
- How do you make a custom post type invisible for subscribers
- I cannot access but but wp-admin works normally
- Can access main URL and Dashboard but not any posts or pages [closed]
- How can I remove “Add new” button on custom post type
- WordPress install checking permissions of user id 0
- Allowing users to edit only their page and nobody else’s
- How to bulk change user role to “No role for this site”
- Restrict Access to the User Profile
- Is it possible to restrict a specific user to edit a specific custom post.
- Custom User Role
- each user having category with their name and can add sub categories post in that category
- Control Category of each user can post
- Split post edit screen into sub-edit screens for users, is this good or bad, and is it possible?
- Suggestions for allowing basic users to view their own posts?
- Front-end ajax problem all users and guests getting a 302 redirect when accessing wp-admin/admin-ajax.php
- Two users attempt to modify a page