我已经发布了以下代码。每当我登录时,$ username都没有执行,因此留空。
function my_login_redirect( $redirect_to, $request, $user ) {
global $current_user;
$current_member = wp_get_current_user();
$username = $current_member->user_login;
$url = home_url( "/connections/$username/profile/edit/group/1/" );
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return esc_url( $url );
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );