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 );

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'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.

| improve this answer | |
  • Hmmm. I tried adding the filter as prescribed. It has done something (of course) but not what I expected. I assume this is directly related to your note @mikengarrett. The output basically added two urls together as follows: bandsondemand.org/signup/bandsondemand.org/signup which throws down a 404 obviously. This is a step forward but not quite to where I want to be! I will look at the return coding and see if I can figure it out but if anyone can point the way forward, I'd appreciate it. – Lee Ness Apr 24 '19 at 17:41
  • Sorry, I was in a rush and didn't look closely at your method for getting the request URI. The method $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] I had previously does not include the protocol. I've updated my answer to reflect a better method for retrieving the correct url. I highly recommend setting this to a particular url instead of this method. – MikeNGarrett Apr 24 '19 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.