Because it’s not working for me. This code checks if a user has just registered. I want to redirect him to a custom page if so. Otherwise, redirect him to the homepage or admin page.
function mylogin_redirect($redirect_to, $url_redirect_to = '', $user = null) {
if( $user->ID ) {
$user_info = get_userdata( $user->ID );
// If user_registered date/time is less than 48hrs from now
// Message will show for 48hrs after registration
if ( strtotime( $user_info->user_registered ) > ( time() - 172800 ) ) {
return get_bloginfo('url') . "/custompage/";
} elseif( current_user_can( 'manage_options' )) {
return admin_url();
} else {
return get_bloginfo('url');
}
}
}
add_filter('login_redirect', 'mylogin_redirect');
I get the expected results for the two options but the admin. elseif( current_user_can( 'manage_options' )) { return admin_url(); } doesn’t seem to get parsed.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Probably because the global $current_user isn’t valid yet, which is used by current_user_can().
However, you can use this instead;
if ($user->has_cap('manage_options')) { return admin_url(); }
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0