登录后将用户重定向到自定义URL

时间:2019-07-23 作者:Dreammedia Rulz

我正在使用“无密码登录OTP/SMS和电子邮件-Facebook帐户工具包”进行登录。

我想将用户重定向到http://www.domain.com/author/<username>/screen 他们登录后

这是我使用的代码

$current_user = wp_get_current_user();
if ( is_user_logged_in() ) {
    $redirect = (\'http://www.domain.com/author/\'.$current_user->user_login.\'/screen\'); }
它重定向到http://www.domain.com/author/screen 没有用户名。有人能帮我吗

2 个回复
SO网友:Dharmishtha Patel
function login_redirect( $redirect_to, $request, $user ){
    $URL ="http://www.abcgg.com";
    return $URL;
}
add_filter( \'login_redirect\', \'login_redirect\', 10, 3 );
SO网友:Douglas.Sesar

问题是wp_get_current_user() 只有在可插拔运行后才可用。尝试将代码添加到以后的挂钩:

add_action( \'wp_login\', function () {
    $current_user = wp_get_current_user();
    if ( is_user_logged_in() ) {
        $redirect = (\'http://www.domain.com/author/\'.$current_user->user_login.\'/screen\'); 
    }
});