[wp-trac] [WordPress Trac] #61746: WordPress login redirect issue
WordPress Trac
noreply at wordpress.org
Wed Jul 24 19:28:28 UTC 2024
#61746: WordPress login redirect issue
-----------------------------+------------------------------
Reporter: dipakparmar2007 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 6.6.1
Severity: critical | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Comment (by dipakparmar2007):
{{{
// Hook into the login_redirect filter
add_filter('login_redirect', 'custom_login_redirect', 10, 3);
function custom_login_redirect($redirect_to, $request, $user) {
// Check if the user object is a WP_User instance
if (isset($user->roles) && is_array($user->roles)) {
// Check user role and redirect accordingly
if (in_array('administrator', $user->roles)) {
// Redirect administrators to the admin dashboard
return home_url('/dashboard/');
} else {
// Redirect other users to a specific page
return home_url('/dashboard/'); // Change /custom-page to your
desired page
}
} else {
// Default redirect
return home_url('/dashboard/');
}
}
}}}
This hook is ilso not work in WordPress version 6.1.1 and I set default
themes.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61746#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list