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.

Tagged: 

This topic contains 3 replies, has 1 voice.

Last updated by Andrey 1 month, 1 week ago.

Assisted by: Andrey.

Author Posts
November 29, 2024 at 11:58 am #16459282

baptisteW-2

Background of the issue:
I am trying to resolve warnings on my blog related to WPML. I found warnings generated from the functions prefetchAllIdsFromGuids and prefechAllIdsFromMetas. These functions have a loop that causes errors when keys in $urls are not adjacent. I replaced the loop with a foreach loop to fix the warnings. Can you do this change on WPML directly?

Symptoms:
PHP Warning: Undefined array key in /var/www/html/wp-content/plugins/wpml-media-translation/classes/class-wpml-media-attachment-by-url-query.php on various lines.

Questions:
Can you implement the change to use a foreach loop in WPML directly?

November 29, 2024 at 12:01 pm #16459286

baptisteW-2

For some reasons, your AI replaced all the code I added into my original answer 🙁

The bug in your code is that you are expecting $urls to have adjacent keys, which is not guaranteed.

So, this loop:

                $urls_count = count( $urls );
                for ( $i = 0; $i < $urls_count; $i++ ) {
                        $index = md5( $language . $urls[ $i ] );
                        $this->setItemToCache( null, 'id_from_guid_cache', $index );
                }

must be rewritten as such:

                foreach ( $urls as $url ) {
                        $index = md5( $language . $url );
                        $this->setItemToCache( null, 'id_from_guid_cache', $index );
                }

And the same the in second function for $pathes.

Otherwise, you will access invalid ids and you will also not access all elements since you will stop early.

I have applied this code change and the warning went away.

Can you please do this change (or something of the sort to avoid the warning) in your code to fix the warning for everybody?

November 29, 2024 at 10:10 pm #16461193

Andrey
Supporter

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

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

Thank you for bringing this issue to our attention.

While one of my teammates addresses your ticket, I would like to offer some initial steps to follow.

Are you using the latest versions of the WPML plugins?

Can you replicate the issue on a fresh installation? We need to be able to replicate and confirm the problem in order to make adjustments in WPML.

December 2, 2024 at 5:26 am #16464169

baptisteW-2

Yes, I am using the latest versions of all WPML plugins.

I don't have any fresh installation of WordPress to test.

December 2, 2024 at 1:58 pm #16466563

Andrey
Supporter

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

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

Thank you for your feedback.

No worries, I have created a test installation. Would you mind trying to replicate it? You will find the link in the following private message.

December 3, 2024 at 5:41 am #16469326

baptisteW-2

I have done some testing on the test installation, but without having access to the PHP Logs, I do not know whether the warnings are there or not.

December 3, 2024 at 1:15 pm #16472032

Andrey
Supporter

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

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

Thank you for your feedback.

You can use the WP File Manager plugin as an alternative to FTP. I have also activated the debug.log, which will be generated in the wp-content folder if errors or warnings occur.

I've attached the screenshots for your reference.

WP-File-Manager-‹-Sandbox-—-WordPress.png
Screenshot 2024-12-03 at 15.10.54.png