php - Redirect user to a custom url after logged in

I'm using "Passwordless Login with OTPSMS & Email - Facebook Account Kit" for login.I want to redi

I'm using "Passwordless Login with OTP / SMS & Email - Facebook Account Kit" for login.

I want to redirect user to /<username>/screen after they log in

this is the code I used

$current_user = wp_get_current_user();
if ( is_user_logged_in() ) {
    $redirect = ('/'.$current_user->user_login.'/screen'); }

It redirect to without the username. can anyone help me with this

I'm using "Passwordless Login with OTP / SMS & Email - Facebook Account Kit" for login.

I want to redirect user to http://www.domain/author/<username>/screen after they log in

this is the code I used

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

It redirect to http://www.domain/author/screen without the username. can anyone help me with this

Share Improve this question edited Jul 23, 2019 at 11:48 Dreammedia Rulz asked Jul 23, 2019 at 11:18 Dreammedia RulzDreammedia Rulz 12 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0
function login_redirect( $redirect_to, $request, $user ){
    $URL ="http://www.abcgg";
    return $URL;
}
add_filter( 'login_redirect', 'login_redirect', 10, 3 );

The problem is that wp_get_current_user() is not available until after pluggable is run. Try adding your code to a later hook:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745302392a4621514.html

相关推荐

  • php - Redirect user to a custom url after logged in

    I'm using "Passwordless Login with OTPSMS & Email - Facebook Account Kit" for login.I want to redi

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信