I’m trying the same thing.
WSL has a filter called “wsl_hook_process_login_alter_redirect_to”.
my attempt bellow in my-theme/functions.php:
function wsl_redirect_to( $redirect_to, $user_id )
{
$user = get_userdata($user_id);
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( $user->has_cap( 'administrator' ) ) {
$redirect_to = admin_url();
} else {
$redirect_to = home_url('/members/'. $user->user_nicename );
}
}
return $redirect_to;
}
add_filter( 'wsl_hook_process_login_alter_redirect_to', 'wsl_redirect_to', 10, 2 );
But when this filter is triggered, the user not yet was created by the WSL.
I’m find a way for this works.
(P.S.: Sorry my english)
My dirty solution, but i don’t see another alternative, furthermore the filter to redirect is inaccessible after user authentication.
/**
* WordPress function for redirecting users on login based on user role
*/
function wsl_after_user_registration( $user_id, $provider, $hybridauth_user_profile, $redirect_to )
{
$user = get_userdata($user_id);
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( $user->has_cap( 'administrator' ) ) {
$redirect_to = admin_url();
} else {
$redirect_to = home_url('/members/'. $user->user_nicename);
}
}
add_action( 'wsl_clear_user_php_session' );
wp_safe_redirect( $redirect_to );
die();
}
add_action('wsl_hook_process_login_before_wp_safe_redirect', 'wsl_after_user_registration', 10, 5 );
Inspiration here:
https://wordpress.org/support/topic/new-user-redirect?replies=10