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.
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?
Hello,
I want to make the same redirection but with the login form.
Thank you.
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/
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
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;
}