• In certain plugins I can redirect my registered users to a new url. On this new URL I have third-party embedded forms that have hidden fields that can read in information like the user’s name or email.

    These forms are expecting urls in this format:

    example.com/waitlist/?email=john@doe.com&name=john

    Is there a way to pull out the logged-in user’s data into the URL. I tried using a redirect url like this but it didn’t work:

    example.com/waitlist/?email={user_email}

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @amateurhr
    I don’t know which plugin you are using to set the redirect. How to inject dynamic data to the redirect url will depend on the plugin, allways assuming that it has some sort of support for it.

    Alternatively, you can use a small custom code in your theme functions.php file to redirect users immediately after the login.
    I made this snippet for you:

    function my_allowed_redirect_hosts($content){
        $content[] = 'example.com';
        return $content;
    }
    
    add_filter( 'allowed_redirect_hosts' , 'my_allowed_redirect_hosts' , 10 );
    
    function my_login_redirect( $redirect_to, $request, $user ) {
    
        //is there a user to check?
        if (!empty($user->data)) {
            $user_first_name = get_user_meta($user->ID, 'first_name', true);
            $user_last_name = get_user_meta($user->ID, 'last_name', true);
            $url_parameters = array(
                'name' => $user_first_name,
                'email' => $user->data->user_email,
                'last_name' => $user_last_name,
            );
    
            $base_redirect_url = 'http://example.com/waitlist/';
    
            $redirect_to =  add_query_arg( $url_parameters, $base_redirect_url );
            /*var_dump($redirect_to);
            die();*/
        }
    
        return $redirect_to;
    }
    
    add_filter( 'login_redirect', 'my_login_redirect', 20, 3 );

    Paste it inside functions.php and disable the redirect plugin that you are using.

    Let me know if that works for you.
    Take care

    Thread Starter amateurhr

    (@amateurhr)

    @sjaure I appreciate your help on this. Do you have any idea how to modify the code you wrote above to use for registration (not login)? I can disable the redirect on my registration forms (I currently use Formidable/NextEnd Social).

    Thank you!

    Hey @amateurhr
    I don’t have time to adapt the code right now, but you should be able to adapt it to use this hook: https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_redirect

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Populating URL with dynamic user information’ is closed to new replies.