admin管理员组文章数量:1429919
I've looked on here and found lots of references to this, but none have worked for me, probably because there must be something in the custom code I am modifying that I don't quite understand. Having taken data from pervious posts here is the original parts of the code that I think I needed to modify: Line 124
// Only show the registration form to non-logged-in members.
if ( ! is_user_logged_in() ) {
add_action( 'wp_footer', 'wyz_add_pass_strength_script' );
There is then a large amount of code for the sign up form which results at the end in the following Line 739
$creds = array();
$creds['user_login'] = $registration_data['user_login'];
$creds['user_password'] = $registration_data['user_pass'];
$creds['remember'] = true;
$user = wp_signon( $creds, is_ssl() );
$url = apply_filters( 'wyz_after_login_redirect', home_url( '/user-account/' ), $user, true );
$url = apply_filters( 'wyz_after_register_redirect', $url, $user );
// Send the newly created user to the user account page after logging him in.
wp_redirect( $url );
exit;
The current code takes the user to the account page as stated in the code comment. I want to take the user back to the original page so I added
$redirect = home_url() . '?redirect_to=' . esc_url($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
At Line 126 And modified to
wp_redirect ($redirect)
before the exit. It didn't work. I kinda expected it wouldn't but I'm not sure what to do now. I've left out the rest of the code because I wanted to keep this query succinct, but if it's required, please let me know and I'll edit the post.
I've looked on here and found lots of references to this, but none have worked for me, probably because there must be something in the custom code I am modifying that I don't quite understand. Having taken data from pervious posts here is the original parts of the code that I think I needed to modify: Line 124
// Only show the registration form to non-logged-in members.
if ( ! is_user_logged_in() ) {
add_action( 'wp_footer', 'wyz_add_pass_strength_script' );
There is then a large amount of code for the sign up form which results at the end in the following Line 739
$creds = array();
$creds['user_login'] = $registration_data['user_login'];
$creds['user_password'] = $registration_data['user_pass'];
$creds['remember'] = true;
$user = wp_signon( $creds, is_ssl() );
$url = apply_filters( 'wyz_after_login_redirect', home_url( '/user-account/' ), $user, true );
$url = apply_filters( 'wyz_after_register_redirect', $url, $user );
// Send the newly created user to the user account page after logging him in.
wp_redirect( $url );
exit;
The current code takes the user to the account page as stated in the code comment. I want to take the user back to the original page so I added
$redirect = home_url() . '?redirect_to=' . esc_url($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
At Line 126 And modified to
wp_redirect ($redirect)
before the exit. It didn't work. I kinda expected it wouldn't but I'm not sure what to do now. I've left out the rest of the code because I wanted to keep this query succinct, but if it's required, please let me know and I'll edit the post.
Share Improve this question edited Apr 21, 2019 at 8:03 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Apr 21, 2019 at 7:46 Lee NessLee Ness 91 bronze badge1 Answer
Reset to default 0I'm having a little trouble following the context, but it looks like all you have to do is make use of the filters that are provided in the code you're looking at.
$url = apply_filters( 'wyz_after_register_redirect', $url, $user );
This hook gives you the chance to modify the redirect url before the redirect is performed. You can take advantage of this to send the users where you want them to go.
add_filter( 'wyz_after_register_redirect', 'my_after_register_redirect', 99, 2 );
function my_after_register_redirect( $url, $user ) {
return home_url( $_SERVER['REQUEST_URI'] );
}
You can register your hook by using add_filter
for your own function, my_after_register_redirect
. This will fire the above code when the apply_filters
for wyz_after_register_redirect
is called. The returned string will be used in place of the $url
value.
NOTE: Keep in mind, the Request URI may not be the url you want users to be redirected to. You may have to work around this in another way.
本文标签: loginRedirect user to previous page after signup from custom form
版权声明:本文标题:login - Redirect user to previous page after signup from custom form 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745557051a2663251.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论