تخطي التنقل

الوسوم: 

يحتوي هذا الموضوع 0 ردود ، لديه 0أصوات.

آخر تحديث بواسطة ludekC-3 قبل يومين، 7 ساعات.

يساعده: Dražen.

الكاتب المشاركات
يوليو 4, 2025 في 11:25 ص #17201325

ludekC-3

Background of the issue:
I'm doing another debug of the bug I reported here: https://wpml.org/forums/topic/uncaught-typeerror-illegal-offset-type-in-isset-or-empty-class-wpml-element-translation-php282/. I found out that in some cases, instead of passing just the post ID, the entire post object is being passed to the method as $element_id. I updated WP and WooCommerce and reviewed my customisations, but unfortunately, it didn't help. Link to a page where the issue can be seen: الرابط المخفي

BTW: I added helper function to /wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php and than used it where necessary (in maybe_populate_cache() and get_element_lang_code(), which solved the error.
The function:
/**
* Ensures an element ID is in the correct scalar format
*
* @param mixed $element_id The element ID to normalize
* @return int|null Normalized element ID or null if invalid
*/
private function normalize_element_id($element_id)
{
// Handle case when a post object is passed instead of just the ID
if (is_object($element_id) && isset($element_id->ID)) {
return intval($element_id->ID);
} elseif (is_array($element_id) && isset($element_id['ID'])) {
return intval($element_id['ID']);
} elseif (is_scalar($element_id)) {
return intval($element_id);
}

return null; // Return null for invalid values
}

Symptoms:
The maybe_populate_cache() function is receiving the entire WP Post object instead of just the post ID.

Questions:
What could be causing the maybe_populate_cache() function to receive the entire WP Post object?
Can you help me look for the cause on our end in the right direction?