Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 8 replies, has 2 voices.

Last updated by Bigul 3 years, 8 months ago.

Assisted by: Bigul.

Author Posts
June 30, 2020 at 1:57 am #6480757

rosaB-2

I'm implementing a SSO service, but understandably, it only offers you one return url.
I've tried to enable the language cookie for AJAX, but when I check the cookie during a function called during 'init', it's been changed back to the original language - I thought it was set via javascript? I'm running the check before any output is made.

Example:
Default site language is EN, I switch to IS, click the link to the SSO provider, which then redirects the user to mysite/?query_var=true.
I check for the query_var during 'init', and if it's there, I run a function that checks the value of the 'wp-wpml_current_language' cookie, and it's 'en'.

Site URL: hidden link

June 30, 2020 at 9:15 am #6483653

rosaB-2

I have an idea of hooking into where the cookie is updated, and using the original value to do the redirect, but I can't seem to get it to work. In the same place I'm getting the language cookie back as 'en', if I add the following:

add_action('wpml_language_has_switched', array( $this, 'get_cookie_lang' ), 0, 3 );

and add the function get_cookie_lang() to the class:

	public function get_cookie_lang($code, $cookie_lang, $original_language) {
		echo "\$code = $code<br>\$cookie_lang = $cookie_lang<br>\$original_language = $original_language<br>";
	}

it does not output anything, which leads me to believe the hook hasn't fired by then, but then how has the cookie lang already been changed?

July 1, 2020 at 4:18 pm #6497413

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue.

Please note, WPML cookies are meant to use by WPML only, and using those cookies in other plugins or themes is not recommended.

Therefore please let me know more your requirement and its workflow for a better understanding. So I can consult about this with our team for an expert opinion.

To help you faster, I've enabled debug information for this support ticket. Please see this link for how to get this information from your site and give it to us: http://wpml.org/faq/provide-debug-information-faster-support/

--
Thanks!

Bigul

July 2, 2020 at 1:11 pm #6504835

rosaB-2

I have found a workaround by using the wpml_before_init hook to grab the original language cookie before wpml resets it.

If that is not recommended, please advise, if it should be fine, the thread can be closed.

What I'm doing is developing a plugin to integrate a state-run SSO service (Iceland) - which will guarantee the identity of logged-in users.
I'm developing it first and foremost for a non-profit I volunteer for, but would like to release it as well as I know others are looking for the same functionality.
I want it to support sites running WPML properly (the non-profit site uses it, so I need to do it anyway). The SSO service only allows you to provide one url for it to send the user along with a SAML2.0 token to, so on that page I need to process the SAML2.0 token, and then send the user back to the same language of the site they were on before redirecting the the SSO login page.

Example:
User is on hidden link - clicks on the login link, which takes it to the login page of the SSO service. The SSO service sends the user back to hidden link, where the token is processed and verified, then the user is sent to their account page on the same language they were on previously (IS) -> hidden link (instead of the EN version -> hidden link )

July 3, 2020 at 6:18 am #6510659

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Thank you for the feedback. I have shared the details with our second-tier team for the expert opinion and waiting for their feedback now. We will get back to you as early as possible. Please wait.

--
Thanks!

Bigul

July 3, 2020 at 5:05 pm #6516273

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

We would like to know is it possible to sending the language information to SSO and then using language information when the user comes back. For examples like URL parameter or post request.

--
Thanks!

Bigul

July 4, 2020 at 1:01 am #6517123

rosaB-2

Nope, checked that. Not possible. Would it be more "kosher" if I set my own cookie instead of using the WPML one?

July 4, 2020 at 4:45 pm #6521085

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Thank you for the updates. I have forwarded your feedback to our second-tier team. We will get back to you as early as possible. Please wait.

--
Thanks!

Bigul

July 8, 2020 at 8:18 am #6545385

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Our second-tier team shared the following advice on this. Please check and let me know your feedback.


*wpml_language_has_switched* hook is working when the Current language changes - https://wpml.org/wpml-hook/wpml_language_has_switched/

So when the software hits the direct URL WPML loads the language according to URL which is happening. The proper way is to send the language info in request and receive the same in response. Or while sending request stores the language in Database or custom Cookie then use it later. If not possible then continue using the cookie before WPML reset it.

--
Thanks!

Bigul

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