[英]WordPress registration auto login and custom redirection
我希望我的用戶注冊,自動登錄並重定向到用戶在標題中拋出的鏈接,例如www.example.com/register/?redirect_to=/to/some/link&reauth=1
我已經在\\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
來重定向到請求的頁面 ..
任何幫助將不勝感激..
-謝謝
您應該為此使用適當的鈎子。 嘗試https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_redirect 。
UPDATE2:
將此行添加到您的注冊表中:
<input type="hidden" name="redirect_to" value="/link/to/location/">
其中value是您的目標頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.