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?
- If the current user is an administrator or editor
- Find out if logged in user is not subscriber
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- How to restrict access to uploaded files?
- Execute a function when admin changes the user role
- What the user_status column?
- Allowing an email as the username?
- Grouping users under parent user
- Check if specific username is logged in
- How to update user role without logout
- Post list based on the user that is logged in
- Basic auth WordPress REST API dilemma
- Do not allow users to create new posts and pages
- How to enable the theme editor cap for an editor role?
- How to assign an additional/extra/second user-role to multiple users (of a specific user-role)
- Copy a user from one WordPress site to another
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- How do I properly format the user_role array?
- Is there a simple way to manage capabilities per user?
- Is it possible to get a user with just the password field?
- Redirect after login based on user role (custom login page)
- Users roles, make a page belonging to multiple users
- Tagging users in WordPress
- Redirect after users complete profile form
- Share user table from WP with Drupal
- Log all users out of all locations after 24 hours
- Getting users by specific capability, not role
- add_cap not working with Shop Manager role
- Remove Capabilities from WP admin for specific user role
- User capability for editing their own comments
- What are some best practices for user exit strategy?
- Is there a way to identify a user in a custom REST API method? [duplicate]
- Allow Contributors to Upload Files
- Add a role and give admin priviledges
- Create custom post with custom user rules
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Restrict access to non-wordpress section of site with user roles?
- How do you manage your pages or functions that require logged-in users?
- Load user by specific role
- What’s the correct way to add capabilites to user roles?
- User roles not displaying
- Delete a user from frontend
- Does it matter if the very first user, usually Admin, does not have a user ID of 1?
- Groups and subgroups for permission
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- Change User Role based on Point System Issue
- Using my own user table
- Add number of members to “Right Now” dashboard widget
- How do I modify the user role ‘subscriber’ to allow the user to delete posts
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- How to hide “Change role to” dropdown on Users admin menu
- grant multiple roles access to specific admin menu item
- hide page menu from admin panel for specific users
- How to Moderate Edits to User Profiles?
- Disabling user capability to edit_posts or delete_posts in the front-end
- User Role not showing in Users Screen
- Groups roles & capabilities
- Button for users to upgrade their user role + Button to show current user role!
- Username has been exposed
- Subscriber role – blank page
- Set user role on registration so can upload file to own media library area
- How to get only 1 role from user
- User “none” role
- each user having category with their name and can add sub categories post in that category
- Giving users an editable homepage/business directory
- How to change user role setting in members plugin so that user can only edit his own post?
- Increase by one the user counter on specific role
- current_user_can() returning true for capability when the user and role do not have the capability
- Redirect user based on role when they try access a particular page
- determine active user browser at the same time
- How to create a specific role to manage users
- 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