Skip Navigation

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

Problem:
The client was experiencing a fatal error when switching to Spanish content, with an error message indicating an 'InvalidArgumentException'
Solution:
We're not sure about what's causing the issue because our developers couldn't reproduce it on our servers but here is a quick workaround.

1. Access your server files using FTP or Cpanel.
2. Navigate to

wp-content/plugins/sitepress-multilingual-cms/classes/wp-core-hooks/post/

and edit the file named

class-wpml-remove-pages-not-in-current-language.php

.
3. Around line 34, locate the following line of code:

$filtered_posts = $posts;

4. Replace it with:

$posts = (isset($posts) && is_array($posts)) ? $posts : array();

This workaround should help you bypass the error.
If this solution doesn't look relevant to your issue, 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 23 replies, has 3 voices.

Last updated by markW-54 1 year, 5 months ago.

Assisted by: Nicolas V..

Author Posts
December 6, 2023 at 7:53 pm #15011963

markW-54

FYI - I have just set the site back to use the Classic translation editor for both new and previously created posts. Feel free to change any settings you like.

Eamonn

December 6, 2023 at 8:09 pm #15012013

markW-54

Further testing. I have just done the following:

1) I deleted the Spanish translation for the page Accommodation (I listed all Spanish pages, deleted the Spanish translation of the accommodation page and permanently deleted the page from trash).
2) Using the classic editor, I started the process of adding a Spanish translation.
3) I pressed "overwrite with English content" and pressed OK to the warning popup.
4) My intention was then to press "Translate independently". However, before I could do this the "InvalidArgumentException" was displayed. See screenshot.

I believe that this test result is significant.

accomm-error-0612-20-09.jpg
December 7, 2023 at 12:57 am #15012689

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you for the updates! I have made sure to include them for our team.

Regarding your move from the Advanced Translation Editor to the Classic Editor, I understand you said you do not want to use the Advanced Translation Editor and Automatic Tranlsation, however, do note that you can remain using the Advanced Translation Editor even without the automatic translation.

This is important as if you do your translations in the Advanced Translation Editor they do not copy over to the classic editor.

The classic editor saves the translations in the database whereas the advanced translation editor saves them in the cloud therefore the 2 do not communicate.

When I edit the Accommodations page for example, If I switch to the advanced editor and access the translation I can see that this was the editor used before.

Nevertheless, even though I switch back to the ATE and update the default language and translation the issue is still triggered. Once I have some updates from our team I will update you.

Screen Shot 2023-12-06 at 4.51.58 PM.png
December 11, 2023 at 12:23 am #15032569

markW-54

Hi there,

I'm keen to get an update on this issue. It has happened again with another site. I have just copied this site (hidden link) over to Siteground at this URL (hidden link). We are seeing exactly the same problem - when we try to view the Spanish translation of any page other than the homepage we get the same error:

Fatal error: Uncaught InvalidArgumentException: target should be an object with filter method or an array in /home/customer/www/website2023.ailmalaga.com/public_html/wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Fns.php:207 Stack trace: #0 [internal function]: WPML\FP\Fns::WPML\FP\{closure}(Object(Closure), false) #1 /home/customer/www/website2023.ailmalaga.com/public_html/wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/functions.php(154): call_user_func_array(Object(Closure), Array) #2 /home/customer/www/website2023.ailmalaga.com/public_html/wp-content/plugins/sitepress-multilingual-cms/classes/wp-core-hooks/post/class-wpml-remove-pages-not-in-current-language.php(48): WPML\FP\{closure}(false) #3 /home/customer/www/website2023.ailmalaga.com/public_html/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php(2269): WPML_Remove_Pages_Not_In_Current_Language->filter_pages(false, Array) #4 /home/customer/www/website2023.ailmalaga.com/public_html/wp-includes/class-wp-hook.php(31 in /home/customer/www/website2023.ailmalaga.com/public_html/wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Fns.php on line 207

This is now getting extremely frustrating - we need to get these sites live and this WPML malfunction is standing in the way. I'm struggling to understand why we're seeing errors with multiple site, but not with this site - hidden link. In terms of inheritance, this site is the sibling of website2023.ailmalaga.com and the parent of website2023.ailespanol.com. I can't understand why one site works perfectly but the other two fail.

Could you let me know what your 2nd line team has discovered?

Many thanks,

Eamonn

December 11, 2023 at 12:41 am #15032697

markW-54

I've been looking through your support log and I have found this brief thread from May 2022:

https://wpml.org/es/forums/topic/fatal-error-al-ver-la-web-en-ingles/

The thread describes exactly the same issue as the one we are seeing. The thread is also marked as resolved. Perhaps you could check in with the engineer who handled this support request (https://wpml.org/es/forums/users/carlos-r/)

All the best,

Eamonn

December 11, 2023 at 11:50 pm #15041425

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello Eamonn,

Bobby is not available today. I just wanted to let you know that your ticket as been escalated to a higher level.

Bobby or I will get back to you as soon as we have some feedback.

December 12, 2023 at 8:43 am #15043137

markW-54

Thanks Nicolas,

Much appreciated.

Eamonn

December 12, 2023 at 1:48 pm #15046615

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello,

We're not sure about what's causing the issue because our developers couldn't reproduce it on our servers but here is a quick workaround.

- Access your server files via FTP or Cpanel
- Edit wp-content/plugins/sitepress-multilingual-cms/classes/wp-core-hooks/post/class-wpml-remove-pages-not-in-current-language.php
- Around line 34 replace:

$filtered_posts   = $posts;

- With:

$posts = (isset($posts) && is_array($posts)) ? $posts : array();

PS: They already applied that fix on your staging site.

December 18, 2023 at 1:23 am #15079861

markW-54

Hi Nicolas,

Apologies for the slow reply - I was off work with illness for a few days.

Thank you so much for the workaround - I've applied it to another malfunctioning site and it works there also.

Let's call this issue solved for the time being - I'll open a fresh ticket if it reoccurs.

Many thanks and all the best,

Eamonn

December 18, 2023 at 1:25 am #15079863

markW-54

Thanks for all the good suggestions and for finding a workaround.