The login_redirect hook does seem to be the right hook.
Can you try this :
(Adapted from the Codex )
function redirect_users_by_role( $redirect_to, $request, $user ) {
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
if ( in_array( 'staff', $user->roles ) ) {
if ($admin_url === $request){
return home_url('/resources');
} else{
return $redirect_to;
}
}
} else {
return home_url('/access-denied');
}
}
add_filter( 'login_redirect', 'redirect_users_by_role', 10, 3 );
Related Posts:
- How to turn off redirection from ‘domain.com/login’ to ‘domain.com/wp-login.php’
- PHP If user is logged in & on home page redirect
- Problem with login form
- Infinite loop when logging out using custom login form
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- wp-login.php?redirect_to=https problem
- Redirect users not logged in to the standard login page (and back) from some posts and pages
- wp_login_url always redirects me to wp-admin
- wp-login – unable to redirect user to a custom login url
- Redirect to current URL and append specified URL parameter on unsuccessful login through Elementor login form widget
- Login to wordpress by clicking a link and specifying usernaname and password in url
- Log in / Log Out Custom Button
- Set Cache-Control header for 301 redirects
- Should `wp_login` be used since it’s deprecated?
- Moving code from theme header to functions.php
- Change CSS based on is_user_logged_in
- How to display login form anywhere, when user isn’t logged in, without redirecting?
- How can I open up my administrative panel to everyone?
- Showing latest post without 301 redirect
- Having Issue on Redirecting With Session in WordPress
- Using a $GET parameter from a URL, to redirect to a URL (WordPress)
- WordPress redirect redirecting too many times or not at all
- Using Argument from Function to Re-Direct Visitor (WordPress)
- I am receiving a pluggable.php warning sign on my only http:// page
- How can I add a new row in a separate database when someone registers via WordPress?
- Login redirect. Check user meta and redirect accordingly
- Where to insert redirect code based on http_referer?
- Is this a correct usage of ob_start() in my WordPress project?
- How to allow download url redirection only if user logged in WordPress site?
- One account with multiple logins
- Lost in trying to create user database system
- Shortcode to log user into current URL
- PHP Redirect condition
- PHP getting error when trying to access WP-Admin Dashboard
- I installed WordPress locally now how do I login?
- If user is logged in not working
- Change homepage content if user is logged in – BuddyPress
- Manually Create PHP Page For A Redirect
- Show login greeting above sub-menu links?
- Redirect to current user page upon link click
- Ajax URLs without #!, how to prevent falling into single.php on load or reload?
- is_user_logged_in returning nothing on custom page
- Writing a link cloaking plugin
- WordPress permalink issue
- WP insert post Redirect after function has executed
- Help with accessing wp-admin page and resolving error messages
- How to redirect non logged in mobile users to page on same site?
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Download file and redirect to page or vice versa
- Add more user roles to a PHP logout redirect function [closed]
- Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
- Can’t log in to WordPress wp-admin after adding code to functions.php
- 404 on old link after changing post url
- WordPress url By country code?
- Check if user had autologin & if so, logout
- how can i redirect dynamic URL in worpress base on ID in htaccess or wp-config or function.php
- Admin Panel 404 Error after login
- PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
- How to block specific user id in custom login form?
- Log out without confirmation request (nonce)
- Implementing a multilingual WordPress site by installing several instances of WordPress and redirecting
- WordPress on Ubuntu – “File not Found” for home.php – Trying to Redirect to Root Folder
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Call WP Rest-Api to GET /users/me returned NOTHING in console
- Remove all feeds and return custom 404 page
- Restrict wordpress access to logged users only
- Menu not updating for logged in users after redirect
- how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
- Issues adding Recaptcha v3 to WordPress Registration
- Redirect User when they click Menu Option
- Display specific page if user signed in
- Change Login or Logout text based on status
- WordPress: Redirect Main Site to Subsite in Multisite Where user is NOT logged in
- Refresh page after login with litespeed cache
- Redirect after login depending on the URL
- Redirecting the lost password page request when using a custon login page
- How do I send a POST request with params with WordPress REST API
- is_user_logged_in() not working in homepage
- ERR_TOO_MANY_REDIRECTS / To Force SSL Logins and SSL Admin Access
- WordPress Redirect / Add_Rewrite_Rule – Non Index.php Page
- Check if a user is logged into my WordPress site which is on a different server
- Override 404 when navigating to single php file
- Newbie question. Login/Registration. New PHP page
- Submit to itself don’t work
- Adding a sidebar to wp-login.php
- redirect 301 with special character like WIX site “#!”
- 301 redirect from webpage to wordpress page in the same root
- Submitting my form to the database and then redirecting to payment site
- List users in a dropdown for login
- Not logged in when using http
- add bootstrap modal after login in wordpress
- White screen after login attempt
- 3 domains, 1 wordpress install, redirecting and changing domains on live site
- Get permalink for a post from inside WordPress and route to a related site
- Link to external page has wordpress blog-url inside
- How to replace wp-admin login page to another location?
- How to use multiple 404 Error Pages in WordPress
- Check user last login date
- Prevent users from display default wordpress login form
- login redirect based on user role not work as expected