This thread is resolved. Here is a description of the problem and solution.
Problem: You are encountering a PHP error 'Undefined array key 4' in the WPML Media Translation plugin. This error occurs because the array keys are filtered out, making the array have non-consecutive keys. This issue is present in the file wp-content/plugins/wpml-media-translation/classes/class-wpml-media-attachment-by-url-query.php at lines 99 and 163. Solution: We recommend modifying the code to handle arrays with non-consecutive keys correctly. Instead of using a for loop, switch to a foreach loop. Here is the corrected code:
Please note that this solution might be outdated or not applicable to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket.
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.
Background of the issue:
wp-contentpluginswpml-media-translationclassesclass-wpml-media-attachment-by-url-query.php
line 99
Same issue also in line 163
Which then means the array isn't a list anymore, but an array with non-consecutive keys and you need to either change it to a foreach loop or check with isset in
our 2nd tier checked but we could not reproduce the issue. More details would be necessary. Even when we process the attachments, we always get at least one element in an array and no warnings or errors.
Can you please share more details and steps to reproduce the issue?
I am providing a test site if you can maybe show us the bug there: hidden link
Sorry, but seriously, this is such a basic issue even the most basic static analysis tool catches.
Purely from looking at your code it should be clear what the problem is, I even provided the fix (which somehow got messed up by your markdown/tag handling it seems)
>we always get at least one element in an array
I think you don't understand why your code produces that notice. It's not about whether you get one element or not. It's about whether the array is a list (= array with linear, monotonously increasing int keys) or not. Initially $urls is a list type, but then array_filter can make it into a generic array type where some keys can be missing, which then leads to the notice further down.
thank you for getting back, but as said we are not able to reproduce the same issue or cause such an error message which is why we need your further help.
We would need to confirm the issue before escalating it to our developers.
It would be very helpful if you could provide us a test case or steps to reproduce the issue in a new install and maybe PHP/DB versions.
I will share your reply with our 2nd tier, but we can not promise that we will be able to confirm and fix this in future versions, without having more required information.
thanks, I will be closing this ticket for now, since you already have a workaround that you provided.
Kind regards,
Drazen
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.