I’m not sure you are using the most correct way to restrict so maybe someone else can chime in but this if statement is grabbing the first role in the array which may be dealer or maybe another role if ( 'dealer' === $role_name ) {
Try instead if ($current_user->has_cap ('dealer')) { the has_cap function on a WP user will check the users capabilities AND roles https://codex.wordpress.org/Class_Reference/WP_User
Or this function https://codex.wordpress.org/Function_Reference/current_user_can
if (current_user_can('dealer'))
Also make sure that you have the correct capitalization ‘Dealer’ vs ‘dealer’
Related Posts:
- Allowing users to edit only their page and nobody else’s
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- Hide Admin Menu for Specific User ID who has administrator Role
- BuddyPress | Check if user is in current group [closed]
- How to customize wp_signon()
- 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
- Hide everything on site for visitors except specific page IDs
- Managing Users and Creating Groups [closed]
- How to disable a specific page for a specific user
- wordpress user roles are not working
- Displaying different in-page content to cliente/admin
- Problem with automatic role change through cron job
- How can I allow an User to publish only 5 posts per month?
- Where are $current_user->allcaps set?
- Allow admins to login as other users
- Can I Create a Second Admin Level User Role?
- WordPress user role with create user capability?
- Update user role for expired membership
- 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
- Control Category of each user can post
- Limit user access to installing/configuring a plugin?
- How to remove/limit Editor accounts privileges, to prevent them from deleting media and pages created by Admin
- Editor can create any new user except administrator
- How to allow an user role to create a new user under a role which lower than his level only?
- How to programatically change username (user_login)?
- Remove Ability for Other Users to View Administrator in User List?
- alphabetically order role drop-down selection in dashboard
- How to let contributors to create a new revision(draft) editing their published posts
- How to hide media uploads by other users in the Media menu?
- Show admin bar only for some USERS roles
- How to check user role without using current_user_can()
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- How to assign capabilities to user NOT to User Role
- How to stop a user from updating the post date
- Return ID of authors who have at least one post
- WordPress edit_user_profile_update update secondary role
- Front end user meta options for users
- How to get the Role Name of the current user? (WordPress)
- set_role has no effect
- WP_User->add_role producing unexpected results
- How do I list in the backend all users that were assigned to a custom role?
- How to add local users to wordpress without email password?
- Get User Role by ID not working
- show text If special user is logged
- Upgrade Nightmare – No Posts, Permissions Issues and Can’t Create a new post
- remove/hide pages from users backend
- Are User Levels Still Currently Used?
- Error: How to allow the “contributor” to upload media in wordpress
- Allow user access to Dashboard only!
- Restrict access of admin uploads to certain logged-in users?
- Removing all trace of member profiles
- Fix permissions for users role
- Reset Password policy
- Is possible to allow user to login with different role?
- How change user type from contributor to author
- How do I let contributors edit their posts after being approved once?
- Load user by specific role
- Fix ‘Add Role’ Option not there in wordpress 5.2.2
- Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
- Customising “user ids” and add to ‘user’ panel in the admin area
- Unique password to access a section site
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- how do I add role and capability after I create a new user
- Get Authors Role
- Using my own user table
- Add number of members to “Right Now” dashboard widget
- Editor role can only create/edit/delete users who have one of two roles
- Find count of WordPress users by role and search string for user name
- Hook into add_user_role and update based on new and removed roles
- fine-grained capabilities for user related capabilities
- Updated user role inncorrect when using wp_get_current_user()
- How to use url formatter with integer
- In admin manage users page, how can I stop users with certain privileges from editing users with other privileges?
- Groups roles & capabilities
- Show user details only
- throttle/limit a logged in user’s http requests to specific page on a per day basis
- Access level seems to have gone from admin to editor
- post acces for guests / unregistered users only
- Subscriber role – blank page
- Set user role on registration so can upload file to own media library area
- Front end login and page restriction
- User “none” role
- view and update form only for registered users
- i need to let a user to add a role from a frontend form
- file upload user profile
- How to give different user access to different people?
- Increase by one the user counter on specific role
- Show only users with the same role in Dashboard user list
- Redirect user based on role when they try access a particular page
- determine active user browser at the same time
- MySQL query to list users who never signed in
- Send email to user if their role is changed to Author
- Remove My Account Menu items in Woocommerce based on user roles
- WordPress: New user role which is ONLY allowed to manage media
- (How) does WordPress protect direct access of user data?
- How to allow users in wordpress to switch between two assigned roles e.g. Candidate & Employer