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 2 replies, has 1 voice.

Last updated by desireeM 3 days, 11 hours ago.

Author Posts
February 16, 2025 at 10:37 am #16710374

desireeM

Background of the issue:
https://wpml.org/documentation/getting-started-guide/language-setup/enabling-language-cookie-to-support-ajax-filtering/
language-cookie.js

This makes no sense and doesn't work.
If using languages in directories where the language cookie was set in a sub-path, it won't unset it either, since it has '/' hardcoded as path, but when you set it, you use COOKIEPATH constant (CookieLanguage.php line 66)

For whatever arbitrary reason you decided that if the user isn't logged in, it will load that JS (CookieLanguage.php), which effectively breaks things when page caches are used (since you can also page cache when users are logged in, any dynamic parts can be e.g. ajax loaded or with subrequests)

Also why do you need a cookie in the first place? You can infer the language from the domain (or subdirectory if language in directories) in the AJAX request anyway.

Symptoms:

Questions:
Why is the path hardcoded as '/' instead of using COOKIEPATH?
How is this supposed to work with page caches?
Why is a cookie needed if the language can be inferred from the domain or subdirectory?
Can you perhaps provide 1 example of a plugin action where the cookie of https://wpml.org/documentation/getting-started-guide/language-setup/enabling-language-cookie-to-support-ajax-filtering/ is necessary and it won't work otherwise?

February 16, 2025 at 10:39 am #16710378

desireeM

Bc right now the JS will only remove the cookie, not set anything, despite even your code comments being aware of that issue.
wpml-request.class.php:

	 * When user is not logged we must set cookie with JS to avoid issues with cached pages
	 *
	 * @param string $lang_code
	 */
	public function set_language_cookie( $lang_code ) {

Which is right, the issue is just that the JS doesn't do what it's meant to do?

February 16, 2025 at 10:41 am #16710380

desireeM

In your code there is an issue link @see hidden link however that's not publically accessible, could you perhaps let me know the details in there?