The profile-update URLs for User Profiles are language specific: .../nl/profile.php
and .../en/profile.php
. When users click “Update Profile” I can redirect them to any URL. But now I want to test the current URL to see if there’s /nl/
in there, so I can give them a redirect to their own language. I use the code below but the result of the ‘if statement’ is always false
. I can see that: when I enter another url there, it picks up that one. So the code seems to work, just the test fails. Any ideas what I’m doing wrong?
add_action( 'profile_update', 'custom_profile_redirect', 12 );
function custom_profile_redirect() {
if(strpos("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}", '/nl/') === false ) {
wp_redirect( trailingslashit( home_url() . '/en' ) );
} else {
wp_redirect( trailingslashit( home_url() . '/nl' ) );
}
exit;
}
[edit:] Variables I managed to retrieve are all set to ‘en’ after the profile update, even the plugin’s global variable. I now worked around it by adding a LanguagePreference dropdown in the sign up form. In the After-Update-Redirect, I read the usermeta and redirect to their own preference.
There must be better ways to achieve this…