最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Redirect user to a custom url after logged in

programmeradmin1浏览0评论

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'); 
    }
});
发布评论

评论列表(0)

  1. 暂无评论