WPML issue, language cookie reset by cookie php js file
-
I have noticed an issue with this plugin and WPML. I have tested it on a clean install.
- WordPress 6.3.1
- Cookies och Content Security Policy 2.17
- WPML Multilingual CMS 4.6.6
- WPML String Translation 3.2.8
When a logged in user switch language and loads a page the “wp-wpml_current_language” cookie is first set to the selected language, for example “en”, but then when js/cookies-and-content-security-policy-error-message.php is loaded the cookie is changed back to, what I guess is the site default language, in my test case “sv”.
When loading the page in Chrome I can see the cookie change in real time.
In the request headers to this php file the cookie is “wp-wpml_current_language=en”. But in the response header there is a “Set-Cookie” header with “wp-wpml_current_language=sv; …”.
Im guessing it is something with how this php file loads WP by including the wp-load.php file but then it just outputs the javascript content without using filters or actions. So Im guessing some WPML hooks are not triggering. Somehow. But Im guessing (swedish “killgissar”) a bit. ??
But deactivating the cookie plugin removes the issue. And adding a “die;” row in the top of js/cookies-and-content-security-policy-error-message.php (line 8 for example) also fixes the issue. But then, of course, the error message js thing is not included.
I can only recreate the issue when Im logged in. It works as expected when browsing the site as a guest.
Maybe a better solution here would be to render the js file and store it in the uploads directory anytime when any of the plugin settings are changed in wp-admin. Would also make the request quicker and easier to cache.
We use this plugin on a lot of sites we do. It works well in its simplicity. Not a lot of sites with WPML though. And this is the first time noticing the issue. Not sure when it appeared. Feel free to reach out to me on [email protected] as well as public responses here if you have any ideas.
/David
- The topic ‘WPML issue, language cookie reset by cookie php js file’ is closed to new replies.