Login Redirect
-
Hey I am using your plugin on my site. I have some specific needs to redirect certain user roles to particular pages. I have this working with the general WordPress login but if the user logs in using their social accounts (only google setup currently). They are redirect back to the home page, not following my setup redirects.
Please see below the code that I am using for the redirect.
// Send new users to a special page function redirectOnFirstLogin( $redirect_to, $requested_redirect_to, $user ) { // URL to redirect to $redirect_first_url = '/students-welcome'; $redirect_stuednts_url = '/students-hub'; // How many times to redirect the user $num_redirects = 1; // If implementing this on an existing site, this is here so that existing users don't suddenly get the "first login" treatment // On a new site, you might remove this setting and the associated check // Alternative approach: run a script to assign the "already redirected" property to all existing users // Alternative approach: use a date-based check so that all registered users before a certain date are ignored // 172800 seconds = 48 hours $message_period = 172800; // If they're on the login page, don't do anything if( !isset( $user->user_login ) ) { return $redirect_to; } $key_name = 'redirect_on_first_login'; // Third parameter ensures that the result is a string $current_redirect_value = get_user_meta( $user->ID, $key_name, true ); if (in_array( 'student', (array) $user->roles )){ if( strtotime( $user->user_registered ) > ( time() - $message_period ) && ( '' == $current_redirect_value || intval( $current_redirect_value ) < $num_redirects) ) { if( '' != $current_redirect_value ) { $num_redirects = intval( $current_redirect_value ) + 1; } update_user_meta( $user->ID, $key_name, $num_redirects ); return $redirect_first_url; } else { return $redirect_stuednts_url; } } } add_filter( 'login_redirect', 'redirectOnFirstLogin', 10, 3 );
It seems to me as though your plugin isn’t honoring the WordPress built in login_redirect hook. Any help in fixing this would be greatly appreciated!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Login Redirect’ is closed to new replies.