Skip to content Skip to sidebar

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.

This topic contains 9 replies, has 2 voices.

Last updated by markusl-22 3 years, 7 months ago.

Assisted by: Dražen.

Author Posts
November 23, 2021 at 1:59 pm #10052327

markusl-22

Hello WPML Team,

I have started to translate my page from english to 6 different languages. An error is created with the point I create a new translation (Translatation cration -> copy english content -> Save). The page can not be saved because a fatal php error happend during the handling of the attached media.

Wraing: Trying to access array offset on value of type bool in /public/wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-image-translate.php on line 113

In PHP 8 this generates an big issue:

PHP Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /public/wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-image-translate.php:113

It looks like the image (svg) attached to page has an empty result for wp_get_attachment_metadata().

What I have done/tried:

In my stage I've reseted your plugin and setup everything new. This fixes the error. But I could not do this on the public page.

I could resave the attached image in the media library, this fixes the meta data issue and your script is running. But I could not do that for every image of my page.

I've clicked on every button in your support->trouble shoot page. Only the reset everything seems to work, but is no option.

With more pages changing to PHP8 you will have this issue on other webpages too. Do you have any suggestions or ideas how to fix this.

All the best,
Markus

November 24, 2021 at 8:02 am #10057445

Dražen
Supporter

Languages: English (English )

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

Hello Markus,

Welcome to WPML Support.

I'll do my best to help you solve this issue.

Can you please check for updates and update WPML plugins to the latest versions (WPML 4.5+):

- https://wpml.org/faq/install-wpml/#wpml-4-2-8
- https://wpml.org/account/downloads/

Please check if the issue still happens.

If the issue still happens, please check and confirm if the issue still happens when using WP default theme, and all other plugins disabled except for WPML plugins.

Let me know how it goes.

Thanks,
Drazen

November 24, 2021 at 10:24 am #10058589

markusl-22

Dear Drazen,

I'm so sorry, I've updated all wpml plugins based on the downloads in my account. I've deactivated every plugin except wpml. I have clicked every button on the trouble shoot page (only left the total reset). The error still exists. Please find my debug log: hidden link

All the best,
Markus

November 24, 2021 at 10:54 am #10058827

Dražen
Supporter

Languages: English (English )

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

Hello Markus,

thanks for getting back.

1) In order to investigate this issue and to understand it better, I would need to access your website.

Please make a full backup of your site (files and database) and confirm it in your next reply. I might need to enable/disable plugins, switch themes and access your website database.

I would need to access both your site's wp-admin and FTP account. Be sure to provide both.

I have enabled the private username and password fields in your next reply.

2) Please share with me step by step guide on how can I check and see the issue.

Thanks,
Drazen

November 25, 2021 at 9:31 am #10066445

Dražen
Supporter

Languages: English (English )

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

Hello Markus,

thanks for getting back.

I could see and reproduce the issue on your website, but I am still missing a few things to understand it completely.

I have also disabled all other plugins and switched to WP default theme while debugging to keep things clear.

1) It looks like the image (svg) attached to page has an empty result for wp_get_attachment_metadata().

Can you please create a new page and reproduce the issue there with a dummy example? If you need to use the Gutenberg block, please use the default one, and not from 3rd party plugins.

That way I can clearly see which SVG file is causing it, and test if it happens with a regular image or new SVG.

2) I could resave the attached image in the media library, this fixes the meta data issue and your script is running. But I could not do that for every image of my page.

This could mean the data is somehow corrupted if resaving fixes the issue.

Can you share with me an example file and steps you take to fix this?

3) Does the issue happen with new SVG on new pages also or only with "corrupted" ones? Is the issue reporodicble on clean fresh setup / new post?

Please let me know.

Thanks,
Drazen

November 25, 2021 at 11:24 am #10067635

markusl-22

Dear Drazen,

I've already shared with you a working solution. Please take a look to class-wpml-media-image-translate.php in the shared cloud folder. My point is, yes it is possible the svg files are corrupted. Wp has still some troubles to work with svg.

But like I've written. The issue was resolved after I've reseted your plugin ("Reset and deactivate WPML") and setup everything from the ground. After that the svgs are still with empty attachment_metadata but your the wpml problem was gone. Please understand my point! I was hoping you know what happens because of the reset and why this fixes the issue.

I'm really stuck here -> With the updated version of WPML I was not able to repeat the reset workaround. But this is no option anyway.

I've added a new screen capture (wpml-debugging.mp4) to the share. Just to show you my understanding of the issue. You could also try to delete one of the translations. This causes the same fatal error.

Hope this helps, please don't give up on me!

I've reseted the cloud again.

hidden link

All the best,
Markus

November 25, 2021 at 2:29 pm #10068953

Dražen
Supporter

Languages: English (English )

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

Hello Markus,

thanks for getting back and sharing a video, that makes it a bit more clear and your feedback is indeed helpful.

Please note I am not giving up, as you said, or trying to close this issue.

I am only trying to clear up the issue and follow our workflow, so I can confirm and check if it is a WPML bug and escalate it quickly to our developers, or if it is a specific bug to your setup to escalate to the 2nd tier for further checkup and debugging.

Thus being the case, can you please get back to me on the next questions:

1) Do you think it would be possible to reproduce the same issue in a simple dummy example on a new page?

2) If you have control over your PHP settings, can you please confirm this issue doesn't happen with the PHP version before 8.0?

3) Would be okay we take a copy of your website for further debugging?

Please let me know.

Thanks,
Drazen

November 25, 2021 at 3:07 pm #10069237

markusl-22

Dear Drazen,

thanks for the follow up. Yes the issue is gone in a PHP 7 enviroment. In PHP your script only logs an "Warning". I will try to reproduce the issue on a dummy wp installation. This will take a little bit of time.
All the best,
Stefan

November 26, 2021 at 6:53 am #10072507

Dražen
Supporter

Languages: English (English )

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

Hello Stefan,

thanks for getting back and understanding.

I appreciate the effort, please take your time and let us know how it goes.

Thanks,
Drazen

November 29, 2021 at 7:35 am #10084877

markusl-22

My issue is resolved now. Thank you!!!

I think the issue was not coming from the WPML plugin. It was just multiplied by it. All images with empty attachment_metadata Data are duplicated because of the translating process. So the initial issue was also duplicated.

My solution is to repair the images with empty attachment_metadata. This is my Script:

function nmsDev($atts) {
	$count = 0;
	$output = '';
	$attachments = get_posts(array(
					'post_type' => 'attachment', 
					'posts_per_page' => -1,
					'post_mime_type' => 'image/svg+xml',
					'fields' => 'ids'
					));
					

	foreach($attachments as $attachment_id){
		$meta_data = wp_get_attachment_metadata( $attachment_id );

		if (empty($meta_data) ){
			
			error_log("Indy tells you - rebuild attachment_metadata: ".$attachment_id);	
			if (!function_exists('wp_generate_attachment_metadata')) {
				// Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
				require_once ABSPATH . 'wp-admin/includes/image.php';
			}
			
			$url = get_attached_file($attachment_id);
			$attach_data = wp_generate_attachment_metadata($attachment_id, $url);
			wp_update_attachment_metadata( $attachment_id,  $attach_data );
			$count++;	
		}	
	}
	$output .='Updated entries: '.$count;
	return $output;
}