How to pass redirect_to from login to registration page in Wordpress

I'm trying to pass the redirect_to querystring to the registration page so individuals who don't have a login, need to register, get redirected back to login page's referrer. I used

wp_login_url(get_permalink($event->get_id())) 

to add the redirect_to querystring to the login page, and tried to use get get_query_var( 'redirect_to' ), but nothing happens.

Anyone know how to add the login querystring on redirect to the register page?

Answers


Figure it out, the applied filter in login.php allows tweaking of the url. I put the code below. The only thing missing is a message stating "You've successfully registered, your password should arrive in the mail".

function custom_register_url( $registration_url ) {
    $registration_url = sprintf( '<a href="%s&%s">%s</a>', esc_url( wp_registration_url() ), $_SERVER["QUERY_STRING"], __( 'Register' ) );
    return $registration_url;
}
add_filter( 'register', 'custom_register_url' );

If you're looking to maintain the redirect_to url from the login to the registration and back to the login page, so the user can just enter their password once received by email, and still return to the original referrer this is the full solution.

function custom_register_url( $registration_url ) {
    $redirect_to = $_GET["redirect_to"];
    $eab_msg = $_GET["eab"];

    if( $redirect_to != "" && $eab_msg != ""  ) {
        // change query name values to prevent default behaviour (redirect_to to uct_redirect)
        $registration_url = sprintf( '<a href="%s&%s&%s">%s</a>', esc_url( wp_registration_url() ), "uct_redirect=" . urlencode($redirect_to), "uct_eab=" . urlencode($eab_msg), __( 'Register' ) );
    }

    return $registration_url;
}
add_filter( 'register', 'custom_register_url' );

function custom_registration_redirect($registration_redirect) {
    $redirect_to = $_GET["uct_redirect"];
    $eab_msg = $_GET["uct_eab"];

    if( $redirect_to != "" && $eab_msg != ""  ) {
        // change query names back to original values (uct_redirect to redirect_to)
        $registration_redirect = wp_login_url( $redirect_to ) . '&eab=' . $eab_msg;
    }

    return $registration_redirect;
}
add_filter( 'registration_redirect', 'custom_registration_redirect' );

Just drop it in functions.php. Hope this helps someone Cheers!


Need Your Help

how to set up visual studio 2005 for cuda programming

c++ cuda nvidia gpu-programming

I have tried to setup my visual studio environment for programming with cuda,but stil I m getting the errors as cudaMemcpy is unable to resolve..