2017-02-21 147 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