Skip Navigation

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

Problem:
The client was experiencing a fatal error when trying to switch languages on the front page of their website. The error was related to an illegal offset type in the

class-wpml-element-translation.php

file within the WPML plugin.

Solution:
We acknowledged the issue and confirmed that it had been escalated to our development team for resolution. We could not provide a specific date for the fix but assured the client that it would be included in future releases. We also requested that the client continue using their temporary solution, which involved modifying the

maybe_populate_cache

function in the

class-wpml-element-translation.php

file to include an

is_numeric

condition.

Please note that this solution might be irrelevant due to it being outdated or not applicable to your case. If you're experiencing similar issues, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket with us.

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.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Andrey 1 year ago.

Assisted by: Andrey.

Author Posts
January 22, 2024 at 1:33 pm #15211569

jeromeT-2

I am trying to: switch language on front page

Link to a page where the issue can be seen: hidden link

I expected to see: translated page

Instead, I got: a fatal error
---
Warning: Illegal offset type in isset or empty in /home/customer/www/example.com/public_html/wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php

----
We found a temporary solution by modifying a function (maybe_populate_cache) adding a 'is_numeric condition'. File : (/wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php).

	private function maybe_populate_cache($element_id, $trid = false)
	{
		if (!$element_id && !$trid) {
			return false;
		}
		if (!$element_id && isset($this->trid_groups[$trid])) {
			return true;
		}
		if (is_numeric($element_id)) {
			if (!$element_id || !isset($this->translations[$element_id])) {
				if (!$element_id) {
					$sql = $this->get_sql_by_trid($trid);
				} else {
					$sql = $this->get_sql_by_element_ids([$element_id]);
				}

				$elements = $this->wpdb->get_results($sql, ARRAY_A); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
				$this->populate_cache($elements);
				if ($element_id && !isset($this->translations[$element_id])) {
					$this->translations[$element_id] = array();
				}
			}
		} else {
			return false;
		}

		return !empty($this->translations[$element_id]);
	}

Could you take a look at this issue and let us know if it would be possible to patch our modification to the plugin in a future update?

Thank you

January 23, 2024 at 1:58 pm #15217375

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you for contacting WPML support and bringing this to our attention.

I understand you mentioned a warning that could not harm your website, but you also referred to a fatal error.

Could you please clarify if there's an actual fatal error on your site? If so, kindly provide me with more details about it.

January 25, 2024 at 9:23 am #15225071

jeromeT-2

Hello, thank you for your reply.
At the moment we don't have the fatal error because, as I mentioned, we've found a temporary solution by modifying the plugin files directly.

You will find attached an image with the code we modified in the plugin file /wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php.
We had to add a condition with an 'is_numeric' parameter in the 'maybe_populate_cache' function to avoid getting the fatal error when changing language on the website.

The fatal error was as follows: Warning: Illegal offset type in isset or empty in /home/customer/www/example.com/public_html/wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php

My question is whether you're aware of this problem and whether there's a possibility that you'll take into account the modification we had to make for a future update of your plugin.

Thank you

bug.png
January 25, 2024 at 9:54 am #15225316

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you for the update. It seems that you may have experienced the issue described in https://wpml.org/errata/advanced-custom-fields-fatal-error-uncaught-typeerror-illegal-offset-type-in-isset-or-empty-in/.

Could you please try the workaround provided in the link? Don't forget to back up your database before making any changes.

January 25, 2024 at 1:43 pm #15226506

jeromeT-2

Thank you for your reply.
I tried the workaround and it works too. Do you know if an update of the acfml plugin is planned to correct this compatibility problem?
Thank you

January 25, 2024 at 3:37 pm #15227108

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you for the update. So we can confirm that it is the same issue. It has been escalated to our development team for resolution. Unfortunately, I cannot provide a specific date for when it will be resolved, but it will be included in future releases of ACFML.

In the meantime, we kindly request that you provide a workaround to overcome the issue. Once the issue is resolved, the status of the link will be marked as 'Resolved'. Thank you for your patience and understanding.