function redirect_non_vendors() {
global $wp;
$user = wp_get_current_user();
$role_needed = 'vendor';
$page_to_check = 'secret/page/url';
$redirect_url = home_url( '/go-here/' );
if ( ! in_array( $role_needed, (array) $user->roles ) && $page_to_check === $wp->request ) {
wp_redirect( $redirect_url );
exit;
}
}
add_action( 'template_redirect', 'redirect_non_vendors' );
You’ll want to replace three things here:
vendor
: the role that someone has to have to access the page
secret/page/url
: the “particular page” you mention in your question
/go-here/
: the URL to send a user to if they are not the role
Related Posts:
- Redirect after users complete profile form
- If the current user is an administrator or editor
- Editor can create any new user except administrator
- 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]
- Execute a function when admin changes the user role
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- Hide Admin Menu for Specific User ID who has administrator Role
- Grouping users under parent user
- How to update user role without logout
- How to check user role without using current_user_can()
- 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)
- How to stop a user from updating the post date
- BuddyPress | Check if user is in current group [closed]
- WordPress edit_user_profile_update update secondary role
- Redirecting user after updating profile?
- How do I properly format the user_role array?
- How to customize wp_signon()
- Is there a simple way to manage capabilities per user?
- Is it possible to get a user with just the password field?
- How to get the Role Name of the current user? (WordPress)
- Redirect after login based on user role (custom login page)
- set_role has no effect
- WP_User->add_role producing unexpected results
- Can I create users that have access to *some* other users posts instead of all other users posts?
- Users roles, make a page belonging to multiple users
- Tagging users in WordPress
- 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?
- Rule to redirect non logged in User to Custom Registration/login Page in .htaccess file
- Getting users by specific capability, not role
- add_cap not working with Shop Manager role
- How to disable a specific page for a specific user
- Are User Levels Still Currently Used?
- Error: How to allow the “contributor” to upload media in wordpress
- Remove Capabilities from WP admin for specific user role
- wordpress user roles are not working
- Displaying different in-page content to cliente/admin
- User capability for editing their own comments
- Redirect user after successful email change
- What are some best practices for user exit strategy?
- Is there a way to identify a user in a custom REST API method? [duplicate]
- Problem with automatic role change through cron job
- Allow Contributors to Upload Files
- Is possible to allow user to login with different role?
- How to stop redirect if user is already on correct page (Using Case Switch)
- Add a role and give admin priviledges
- Where are $current_user->allcaps set?
- How change user type from contributor to author
- How do I let contributors edit their posts after being approved once?
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- How to check User Role and redirect to specific page according to Role when login in WordPress?
- Restrict access to non-wordpress section of site with user roles?
- Load user by specific role
- What’s the correct way to add capabilites to user roles?
- Fix ‘Add Role’ Option not there in wordpress 5.2.2
- User roles not displaying
- Allow admins to login as other users
- Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
- Can I Create a Second Admin Level User Role?
- How to add array [closed]
- Does it matter if the very first user, usually Admin, does not have a user ID of 1?
- Redirect user to login if not logged in, on specific pages
- Groups and subgroups for permission
- Redirect current user to their most recent custom post
- how redirect users to custom login page when “login to reply” is clicked? [duplicate]
- 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
- 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
- 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
- Redirect /member/ to /member/user
- In admin manage users page, how can I stop users with certain privileges from editing users with other privileges?
- User Role not showing in Users Screen
- Groups roles & capabilities
- WordPress install checking permissions of user id 0
- Button for users to upgrade their user role + Button to show current user role!
- 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
- Subscriber role – blank page
- How to get only 1 role from user
- User “none” role
- Creating Custom user type just like custom post
- Redirect based on log-in status per JavaScript
- Control Category of each user can post
- Giving users an editable homepage/business directory
- Limit user access to installing/configuring a plugin?
- 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
- Show only users with the same role in Dashboard user list
- Remove My Account Menu items in Woocommerce based on user roles
- WordPress: New user role which is ONLY allowed to manage media