[英]WordPress registration auto login and custom redirection
I want my users to register, auto login and get redirected to the link thrown by the user in the header like www.example.com/register/?redirect_to=/to/some/link&reauth=1
我希望我的用户注册,自动登录并重定向到用户在标题中抛出的链接,例如www.example.com/register/?redirect_to=/to/some/link&reauth=1
I have made a file in \\wp-content\\plugins\\theme-my-login-custom.php
我已经在\\wp-content\\plugins\\theme-my-login-custom.php
制作了一个文件
the code is as follows:- 代码如下:
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' );
The auto login is working fine but I cant catch the variable redirect_to
to redirect to the requested page .. 自动登录工作正常,但是我无法捕获变量redirect_to
来重定向到请求的页面 ..
any help will be appreciated.. 任何帮助将不胜感激..
-Thanks -谢谢
You should use appropriate hook for this. 您应该为此使用适当的钩子。 Try https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_redirect . 尝试https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_redirect 。
UPDATE2: UPDATE2:
Add this line into your registration form: 将此行添加到您的注册表中:
<input type="hidden" name="redirect_to" value="/link/to/location/">
where value is your destination page. 其中value是您的目标页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.