Skip Navigation

[Resolved] Redirect user

This support ticket is created 3 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Minesh 3 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#2169759

Hello,

A user is registered by choosing a sport. When he connects, he is redirected to an url related to the sport he has chosen.

Is it possible ? What would the code be?

This code work with cred form :

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==3684){
        $choice = $_POST['wpcf-club'];
        if($choice == "1"){
                return 'ndd1.com';
          }
        if($choice == "2"){
               return 'ndd2.com';
}
              if($choice == "3"){
               return 'ndd3.com';
}
              if($choice == "4"){
               return 'ndd4.com';
}
              if($choice == "5"){
               return 'ndd5.com';
}
              if($choice == "6"){
               return 'ndd6.com';
}
              if($choice == "7"){
               return 'ndd7.com';
}
    }
    return $url;
}

Thank you.

#2169895

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can use the hook "cred_success_redirect" with the Toolset form and when user submit the form.

Do you have Toolset form and you want after user submit the form you want to redirect user to the some custom redirect URLs?

#2170247

Hello,
I want to make the same redirection but with the login form.

Thank you.

#2170557

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is no Toolset hook available for login redirect as Toolset uses the core WordPress login form.

You should try to use the WordPress native hook: login_redirect
=> https://developer.wordpress.org/reference/hooks/login_redirect/

#2175093

Hello,

Like this ?

add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'subscriber', $user->roles ) ) {
// redirect them to the default place
$choice = $_POST['wpcf-club'];
if($choice == "1"){
return 'ndd1.com';
}
if($choice == "2"){
return 'ndd2.com';
}
if($choice == "3"){
return 'ndd3.com';
return $redirect_to;
} else {
return home_url();
}
} else {
return $redirect_to;
}
}

Thank you

#2175103

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - something like that. As this is a default WordPress hook, if you do not get working, you are welcome to contact pro WordPress Devs.

I see mistake in the code.

Here is the correct code that should work:

add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'subscriber', $user->roles ) ) {
// redirect them to the default place
$choice = $_POST['wpcf-club'];
			if($choice == "1"){
			return 'ndd1.com';
			} else if($choice == "2"){
			return 'ndd2.com';
			} else if($choice == "3"){
			return 'ndd3.com';
			} else {
			return home_url();
			}
			
	
}
	}
	return $redirect_to;
}