Skip Navigation

[Resolved] Conditional redirects not working for all roles in German

This thread is resolved. Here is a description of the problem and solution.

Problem:

Redirect users after login on user roles and languages.

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/conditional-redirects-not-working-for-all-roles-in-german/#post-2133533

Relevant Documentation:

This support ticket is created 2 years, 8 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.

Our next available supporter will start replying to tickets in about 0.56 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by simonM-5 2 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2131869

Hi Support

Shane kindly provided us with a custom code snippet "conditional-redirect-on-successful-login". a while back to redirect users based on their role at login.

Everything works as expected in English, but some of the redirects aren't working in German, although we cannot see any issues with page slugs and the pages are translated correctly in WPML. It's not working for roles unverified_nanny or unverified_family.

1) Role unverified_nanny

In EN it redirects successfully to:

$redirect_to = get_site_url() . '/en/become-a-native-nanny-complete-profile'

but in German (DE) it defaults back to the English version instead of going to:

$redirect_to = get_site_url() . '/de/native-nanny-werden-profil-ergaenzen'

2) Role unverified_family

In EN it redirects successfully to:

$redirect_to = get_site_url() . '/en/sign-up-complete-profile'

but in German (DE) it defaults back to the English version instead of going to:

$redirect_to = get_site_url() . '/de/registrieren-profil-ergaenzen'

Thanks and best regards
Simon

#2132223

Hello,

I assume we are talking about the item "conditional-redirect-on-successful-login" in your website Toolset-> Settings-> Custom code,

There isn't such kind of built-in feature within Toolset plugins, and it is a custom codes problem, according to our support policy, we don't provide custom codes support.

And you did not provide the detail steps to reproduce the same problem, so I am not sure where I can debug this issue.

And it should be very easy to debug the PHP codes, for example, edit item "conditional-redirect-on-successful-login", after line 8, you can output the variable $redirect_to directly:

var_dump($redirect_to);
die();

Then test it with a unverified_nanny user in German page, you should be able to see the result of variable $redirect_to, then you can check if it satisfied those conditions of your custom PHP codes.

#2132293

Hi Luo

Yes, as stated in my first line, it was the snippet of custom code provided by Toolset "conditional-redirect-on-successful-login".

You are right, my apologies, it was not clear how to reproduce the problem. If you send me a private reply, I can send you two test logins (one for each of the user roles where the redirect is not working) to investigate with. To reproduce the issue you would just have to log in with those test logins. I am not a PHP programmer myself.

Thanks and regards
Simon

#2132329

Private message box enabled, please provide detail steps to reproduce the same problem.

#2132351

Hi Luo

You can use the following logins:

1) Role "unverified_nanny"
unverified_nanny@example.com / 123
Log on to hidden link to use the German version
Click "Anmelden" (Log in) in the menu and log in

Should land on page: /de/native-nanny-werden-profil-ergaenzen instead landing on the English version /en/become-a-native-nanny-complete-profile

2) Role "unverified_family"
unverified_family@example.com / 123
Log on to hidden link to use the German version
Click "Anmelden" (Log in) in the menu and log in

Should land on page: /de/registrieren-profil-ergaenzen instead landing on the English version /en/sign-up-complete-profile

If you need any more info, please don't hesitate to contact me.

Thanks and best regards
Simon

#2133533

I have setup a demo in your website, edit custom codes "conditional-redirect-on-successful-login", line 57~61:

          if(str_contains($redirect_to, '/de/')){
          	$redirect_to = get_site_url() . '/de/native-nanny-werden-profil-ergaenzen';
          }else{
            $redirect_to = get_site_url() . '/en/become-a-native-nanny-complete-profile';
          }

This should work for "unverified_nanny" users, and it only check if it is in German pages.

#2133909

HI Luo

That worked perfecly! Thanks!

My issue is resolved now.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.