2017-02-21 136 views
0

我希望我的用戶註冊,自動登錄和重定向到在頭用戶拋出的鏈接像www.example.com/register/?redirect_to=/to/some/link&reauth=1WordPress的註冊自動登錄以及自定義重定向

我已在\wp-content\plugins\theme-my-login-custom.php

的文件代碼如下: -

function auto_login_new_user($user_id) { 
    wp_set_current_user($user_id); 
    wp_set_auth_cookie($user_id); 
    if(isset($_REQUEST['redirect_to'])) 
    { 
     wp_redirect('/'.$_REQUEST['redirect_to']); 
    } 
    else 
    wp_redirect('/profile'); 
    exit; 
} 
add_action('user_register', 'auto_login_new_user'); 

自動登錄工作正常,但我不能趕上變量redirect_to重定向到被請求的頁面 ..

任何幫助將不勝感激..

-Thanks

回答

1

應使用適當掛鉤這一點。嘗試https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_redirect

UPDATE2:

添加此行到您的報名表:

<input type="hidden" name="redirect_to" value="/link/to/location/"> 

其中value是你的目標頁面。

+0

可以詳細說明這一點,因爲我仍然在學習WP ... – user287332

+0

試過它什麼都沒有發生.... – user287332

+0

你可以添加'」轉換爲註冊表格?並填寫該值,而不是通過url發送並手動處理。請描述您如何創建註冊表單。 – keyBeatz