• Resolved borie88

    (@borie88)


    Not sure how I couldn’t find anyone else with the same problem. My custom redirect after login is set to referrer, which works fine UNLESS it is a new user who just registered. Users who just registered will get redirected to login. After logging in, the referrer is the registration page, which always ends in a 404 – Page Not Found because they’re logged in… Any way to add a simple conditional that checks if the referrer is the registration page first?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter borie88

    (@borie88)

    For now, I have just added an IF statement below everything in the custom-redirection.php file to modify the _wp_original_http_referer input that is added to check if the referrer is the registration page or not… Works, but seems hacky, is there a better way to do this?

    	public function login_form() {
    		if ( ! empty( $_REQUEST['redirect_to'] ) ) {
    			$referer = wp_unslash( $_REQUEST['redirect_to'] );
    		} elseif ( wp_get_original_referer() ) {
    			$referer = wp_get_original_referer();
    		} else {
    			$referer = Theme_My_Login::is_tml_page() ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
    		}
    		if (($_REQUEST['redirect_to'] === wp_registration_url()) || (wp_get_original_referer() === wp_registration_url()) || (wp_get_referer() === wp_registration_url())) {
    			$referer = get_home_url();
    		}
    		echo '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $referer ) . '" />';
    	}
    • This reply was modified 8 years, 5 months ago by borie88.
    • This reply was modified 8 years, 5 months ago by borie88.
    Plugin Author Jeff Farthing

    (@jfarthing84)

    I would probably just redirect the registration page if the user is logged in:

    function redirect_register_page() {
        if ( Theme_My_Login::is_tml_page( 'register' ) && is_user_logged_in() ) {
            wp_redirect( get_home_url() );
            exit;
        }
    }
    add_action( 'template_redirect', 'redirect_register_page' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Redirection to Referrer – Register -> Login -> Register = 404’ is closed to new replies.