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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 5:00 – 13:00 5:00 – 13:00 5:00 – 13:00 5:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: America/Argentina/Buenos_Aires (GMT-03:00)

This topic contains 10 replies, has 0 voices.

Last updated by Otto 11 hours, 7 minutes ago.

Assisted by: Otto.

Author Posts
September 22, 2025 at 11:12 am #17421346

Natalie Wood

Background of the issue:
I updated the WPML plugins to the latest versions 7 days ago. After that, images are being randomly deleted from my server. It is hard to pin down the exact steps that cause this to happen but it is definitely after doing a translation of a page in the Advanced translation editor. It doesn't happen after every translation though. I put a backtrace in my functions.php file to track what was doing the deleting of the files and it is definitely WPML. This is the backtrace:
[22-Sep-2025 10:33:30 UTC] delete_attachment called for Post ID: 7392
[22-Sep-2025 10:33:30 UTC] Image file /wp-content/uploads/Wave-Connect-video-preview.webp
[22-Sep-2025 10:33:30 UTC] Backtrace:
[22-Sep-2025 10:33:30 UTC] File: wp-includes/class-wp-hook.php, Line: 326, Function: my_delete_attachment_caller_info
[22-Sep-2025 10:33:30 UTC] File: wp-includes/class-wp-hook.php, Line: 348, Function: WP_Hook->apply_filters
[22-Sep-2025 10:33:30 UTC] File: wp-includes/plugin.php, Line: 517, Function: WP_Hook->do_action
[22-Sep-2025 10:33:30 UTC] File: wp-includes/post.php, Line: 6655, Function: do_action
[22-Sep-2025 10:33:30 UTC] File: wp-includes/post.php, Line: 3725, Function: wp_delete_attachment
[22-Sep-2025 10:33:30 UTC] File: wp-content/plugins/sitepress-multilingual-cms/inc/post-translation/wpml-post-synchronization.class.php, Line: 204, Function: wp_delete_post
[22-Sep-2025 10:33:30 UTC] File: wp-content/plugins/sitepress-multilingual-cms/inc/post-translation/wpml-post-synchronization.class.php, Line: 128, Function: WPML_Post_Synchronization->delete_translations
[22-Sep-2025 10:33:30 UTC] File: wp-content/plugins/sitepress-multilingual-cms/inc/post-translation/wpml-post-translation.class.php, Line: 157, Function: WPML_Post_Synchronization->delete_post_actions
[22-Sep-2025 10:33:30 UTC] File: wp-includes/class-wp-hook.php, Line: 326, Function: WPML_Post_Translation->delete_post_actions
[22-Sep-2025 10:33:30 UTC] File: wp-includes/class-wp-hook.php, Line: 348, Function: WP_Hook->apply_filters
[22-Sep-2025 10:33:30 UTC] File: wp-includes/plugin.php, Line: 517, Function: WP_Hook->do_action
[22-Sep-2025 10:33:30 UTC] File: wp-content/plugins/sitepress-multilingual-cms/classes/media-translation/PostWithMediaFiles.php, Line: 221, Function: do_action
[22-Sep-2025 10:33:30 UTC] File: wp-content/plugins/sitepress-multilingual-cms/classes/media-translation/PostWithMediaFiles.php, Line: 160, Function: WPMLMediaTranslationPostWithMediaFiles->delete_duplicated_attachment
[22-Sep-2025 10:33:30 UTC] File: wp-content/plugins/sitepress-multilingual-cms/classes/media/duplication/class-wpml-media-attachments-duplication.php, Line: 673, Function: WPMLMediaTranslationPostWithMediaFiles->delete_duplicated_copied_media
[22-Sep-2025 10:33:30 UTC] File: wp-content/plugins/sitepress-multilingual-cms/classes/media/duplication/class-wpml-media-attachments-duplication.php, Line: 559, Function: WPML_Media_Attachments_Duplication->maybe_clear_duplicated_copied_media_in_posts_queue
[22-Sep-2025 10:33:30 UTC] File: wp-includes/class-wp-hook.php, Line: 324, Function: WPML_Media_Attachments_Duplication->maybe_duplicate_original_post_media
[22-Sep-2025 10:33:30 UTC] File: wp-includes/class-wp-hook.php, Line: 348, Function: WP_Hook->apply_filters
[22-Sep-2025 10:33:30 UTC] File: wp-includes/plugin.php, Line: 517, Function: WP_Hook->do_action
[22-Sep-2025 10:33:30 UTC] File: wp-admin/includes/class-wp-screen.php, Line: 424, Function: do_action
[22-Sep-2025 10:33:30 UTC] File: wp-admin/includes/screen.php, Line: 243, Function: WP_Screen->set_current_screen
[22-Sep-2025 10:33:30 UTC] File: wp-admin/admin.php, Line: 213, Function: set_current_screen
[22-Sep-2025 10:33:30 UTC] File: wp-admin/upload.php, Line: 10, Function: require_once.
This happened after a very minor translation update where I pasted text into two places that weren't anything to do with images. Link to a page where the issue can be seen: hidden link

Symptoms:
Images are being randomly deleted from the server after translating a page using the Advanced translation editor. The issue does not occur after every translation.

Questions:
Why are images being deleted after translation?
How can I prevent WPML from deleting images?

September 22, 2025 at 6:08 pm #17423150

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Your debug backtrace shows the delete call originates in WPML Media Translation’s duplication/cleanup flow, specifically through WPMLMediaTranslation\PostWithMediaFiles and WPML_Media_Attachments_Duplication when WPML thinks an attachment is a duplicated copy to be cleared.

Please try the following:
- Go to WPML → Support → Troubleshooting.
- Run (in this order): Set language information, Fix post type assignment for translations, Assign translation status to duplicated content. Clear caches and retest ATE.

If this does not help, although the backtrace points to WPML it's worth to try the following test. Many times what triggers the problem is a compatibility issue:
**IMPORTANT:** Please try this in a staging environment or at least with a backup of your site files and database before continuing.
Disable all plugins except WPML-related and temporarily change the theme to a default WordPress such as Twenty Twenty-five.
Is the issue resolved with these settings? If so, please reactivate one by one to see which conflicts.

Best Regards,
Otto

September 23, 2025 at 1:27 pm #17425673

Natalie Wood

Thanks
I did the steps as suggested in the Go to WPML → Support → Troubleshooting section

The error was not resolved by that

As I said the error doesn't happen after every translation.

It took 22 times trying the translation before the error happened again, so disabling plugins and testing and then enabling one by one is going to take a huge amount of time.

Unfortunately I can't see a pattern as to what triggers the error.

Note that prior to the update of the WPML plugins there had never been a problem, so it is some issue with the updates.

To narrow it down: at the time I did the WPML updates, I also updated Gravity Forms multilingual and Advanced custom fields. That was all.

Was there an update to the advanced translation editor as well?

Can you give me more information on the situation, whereby WPML decides it has to delete an image?

Note that the last two times only one image has been deleted but other times it was more than one image. But never all the images in the post.

I am testing on my dev site, but the live site has the same issue as I updated the WPML plugins there before I realised this was an issue. Is there any way I can roll-back to the previous versions of the WPML plugins, just so that I can have the live site functional?

Also will it make any difference if I uncheck the: "When deleting a post, delete translations as well" setting? Would that stop image delete?

Thanks for any help you can give as this is a very difficult issue to troubleshoot.

September 23, 2025 at 2:59 pm #17426145

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Yes, I understand how hard and frustrating these kinds of issues are 🙁

You said that it took 22 attempts before you could reproduce the problem. You mean that you saved 22 times the same translation, or you saved 22 different translations until you were able to see the problem?

What kind of images are deleted from the post? I mean, are those regular image attachments or added in a custom field or as a gallery?

In the last version, WPML changed how media is handled:
https://wpml.org/download/wpml-media/?section=changelog
https://wpml.org/changelog/2025/08/wpml-4-8-human-quality-ai-translations/#improved-media-translation

So, which type of media is being deleted can give us a clue.

Did you enable automatic detection in WPML > Settings > Media Translation?

About your questions:

- When does WPML decide to delete an image?
The cleanup runs from the Media module after media auto-handling queues a post for “copied” images. For each image that was duplicated into a translation, WPML checks if the translated attachment still looks redundant (same caption/description/alt as the source). If so, it deletes the translated attachment record.
This deletion is performed by a direct SQL path (not wp_delete_attachment) inside PostWithMediaFiles::delete_duplicated_copied_media → delete_duplicated_attachment. The intent is to remove only the attachment post/meta, not necessarily the physical file.

133:161:/Users/ofwald/Local Sites/for-cursor/app/public/wp-content/plugins/sitepress-multilingual-cms/classes/media-translation/PostWithMediaFiles.php
public function delete_duplicated_copied_media() {
  ...
  if (
    $texts['caption'] !== $translation_texts['caption'] ||
    $texts['description'] !== $translation_texts['description'] ||
    $texts['alt'] !== $translation_texts['alt']
  ) {
    continue;
  }
  $this->delete_duplicated_attachment( $translation->element_id );
}
190:231:/Users/ofwald/Local Sites/for-cursor/app/public/wp-content/plugins/sitepress-multilingual-cms/classes/media-translation/PostWithMediaFiles.php
private function delete_duplicated_attachment( $post_id ) {
  global $wpdb;
  ...
  // Deletes terms/meta, fires delete_post/deleted_post, then:
  $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
  ...
  return $post;
}

The above focuses on the attachment post/DB. In some environments, other processes can remove files once attachments disappear or if they share paths, but the core cleanup uses SQL (not wp_delete_attachment).

- Will unchecking “When deleting a post, delete translations as well” stop image deletes?
No. That setting affects cross-language post deletion, not the media-duplication cleanup. The media cleanup runs independently under the Media module’s logic.
- If you need an immediate mitigation, try turning off automatic media handling (WPML → Settings → Media Translation → “Automatic image and media detection”).

- Was there an Advanced Translation Editor (ATE) update too?
- ATE is SaaS and gets frequent updates, but the behavior change relevant here is in WPML 4.8’s core/media layer (“automatic image and media detection” and the subsequent duplicate cleanup). So the likely trigger is the WPML core/media update, not ATE itself.

Best Regards,
Otto

September 24, 2025 at 5:21 am #17427343

Natalie Wood

Thanks

I don't quite understand from your explanation how the image is being deleted. You seem to suggest that only the DB post is being deleted however it is clear from the backtrace that WPML is deleting the file - so where in the logic does this happen?

One thing that may be relevant is that I create posts in English then translate to Danish however Danish is the default language.

Yes I have checked the "Automatically detect best options for translating image texts" option, however I did turn it off at one point and the images were still being deleted.

The images are added to the post in an image block. My theme is GeneratePress and I use a GenerateBlocks image block for all images. The Post I'm working on has about 23 images.

It was 22 translations of the same post that I did. Each time I did a minor (or no) edit in the English then did the translation to match. I tried various types of edits and translations to see if I could see any pattern.

I have a feeling that there is an issue with ATE. I have noticed some inconsistencies when I open the translation. Sometimes suddenly there is a field that is not translated. During the above testing at one point the slug was suddenly untranslated, although that was not the time the media were deleted.
Sometimes the autotranslate seems to override the translation that is already there with its own translation.

I've attached what shows in ATE for the image that has been deleted the last two times it happened. You can see that the ALT text is different for the translation so it shouldn't think that it is a 'duplicate' at all, Except of course now I realise that that 'ALT' is in the post and the translation is in the post. We never actually do a translation in the media file itself - is that the issue?

I have activity logging on
I have attached the post revision information form the translation I did just before the last time the image got deleted.
I have tried the exact same edit now but the image didn't get deleted, so it really does seem to be random.

Finally please let me know how I can roll back to the previous versions of the WPML plugins

activity.png
deleted-image.png
September 24, 2025 at 5:00 pm #17429949

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Thanks for the detailed explanation.

About rolling back. It’s generally safe—but do it carefully and in lockstep.

- What “safe” rollback means
- Roll back WPML core (sitepress-multilingual-cms) and all WPML add‑ons together to versions that were compatible with 4.7.6 (String Translation, Media Translation, WooCommerce Multilingual, ACFML, etc.).
- Always back up database + uploads first and test on staging before touching production.

- Compatibility notes
- WPML 4.8.x added “automatic image/media detection” and some new options/meta. Rolling back to 4.7.6 will simply ignore those extra options; no schema downgrade is required.
- The Advanced Translation Editor (ATE) is SaaS and unaffected by plugin rollback (jobs/translations remain intact).

- Recommended rollback steps
- Staging: restore a backup or snapshot → downgrade WPML core and its add‑ons together via the Commercial tab (OTGS Installer) or zips from your WPML account → clear caches.
- WPML → Support → Troubleshooting: run “Clear the cache in WPML”, “Set language information”, and “Fix element_type collation” to refresh internal state.
- Verify media, translations, and ATE saves work normally; only then mirror the change on production.

- Will this help with the image deletions?
- Likely yes, if the issue started with 4.8.x media changes.

Back to this weird and random issue:

- What actually deletes the file
- The “duplicate cleanup” WPML runs after ATE saves is designed to delete only the translated attachment record (database row), not the physical file. It does this via a direct SQL delete, not WordPress’s wp_delete_attachment.
- However, if any code path ends up calling wp_delete_attachment on that attachment (Core or another plugin/theme reacting to attachment deletion), WordPress will remove the physical file and its sizes. Since your backtrace shows wp_delete_attachment, we need to pinpoint which hook calls it. That’s not the intended cleanup path in current WPML core.

- Why cleanup might incorrectly classify “duplicates”
- WPML evaluates duplicate-ness using the attachment’s own texts (caption, description, and the attachment’s alt meta), not the alt/caption you see inside blocks. If you translate alt in the block only (not in the media library/attachment), the attachment-level texts may still look identical to the source, and the cleanup may consider the translated attachment redundant.
- Your default language is Danish but you create in English. That can increase mapping edge cases (TRIDs/“duplicate-of” links), especially with the automatic media handling introduced in 4.8. That, plus ATE’s asynchronous saves, can make this feel intermittent.

- Why turning off “Automatically detect best options for translating image texts” didn’t stop it
- That toggle doesn’t fully disable the duplicate cleanup.

- On ATE updates
- ATE (the editor) is hosted and updated independently. The behavior change most relevant here came with WPML 4.8’s media/cleanup logic (“automatic image and media detection”). That’s the likely factor, not an ATE change per se.

Best Regards,
Otto

September 26, 2025 at 1:30 pm #17436149

Natalie Wood

Thanks

*can you advise how to get the previous versions of the WPML plugins - I don't see that option in the "commercial tab"

You have said that "unchecking 'When deleting a post, delete translations as well' won't stop image deletes"

However from the backtrace the call to delete the attachment is coming via:
sitepress-multilingual-cms/inc/post-translation/wpml-post-synchronization.class.php,
Line: 128, Function: WPML_Post_Synchronization->delete_translations

The code around line 128 is:

if ( $this->sync_delete || Lst::includes( $post_type, [ 'wp_template', 'wp_template_part' ] ) ) {
$this->delete_translations( $translated_ids, $keep_db_entries );
}

To me it seems the value of $this->sync_delete is set by:
$settings[ 'sync_delete' ]
*is this not the "When deleting a post, delete translations as well" setting?

There is a lot more I think I need to understand about images before I'm going to get to the bottom of this.

So I've just uploaded a new image in English language. I see that is ISN'T duplicated into Danish language

Then I added the image to a page and translated the page. Then I see that the image IS duplicated into the Danish language i.e. there is a post for it.
*Is this the correct behaviour?

I did translate the ALT text in the page but the duplicated image doesn't get the translated ALT text.
*So what is the use of the duplicate at that point?

You say that:

"Your default language is Danish but you create in English. That can increase mapping edge cases (TRIDs/“duplicate-of” links),"

*Does this mean the WPML doesn't support creating content in the non-default language?

Further to all this there seem to be some inconsistent post-attachment records in the ICL-translations table. These are recent and I suspect they are caused by the images being deleted. They may be part of the problem but I notice in the live database that there aren't any inconsistent records but it also suffered from deleted images. I've attached an image of some of the inconsistent records.
*Can you think how this would happen?

Even if I roll back the WPML plugins on my live site, I will have to keep trying to resolve this on dev . I will keep testing but as it is difficult to replicate the error it may take some time. *Can we keep this issue open?

records.png
September 26, 2025 at 3:11 pm #17436627

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

You can get previous versions going to wpml.org/downloads, expand "Download manually" and the click on the changelog icon for each plugin. Check the screenshot attached, please.

Yes, the behavior is correct, with the latest version attachments are not duplicated until it's needed.

About, creating content in non-default language. It's supported, I meant that in a complex setup it may increase the chance of failure. But we need to understand how it's failing.

Yes, the ticket will remain open for 2 weeks without activity.

About the code you are pointing as the root cause of the problem. I am not sure... As far as I know, when dealing with attachments, WPML does not handle physical files, it handles them at the DB level. But I'd like to take a better look at the issue. Is it possible for you to provide me with a copy of the site? You can use Duplicator or just a DB dump and the wp-content folder. I am enabling a private reply in case it's OK, so you can share a download link safely. If not, I'd try to reproduce it on a test environment.

Best Regards,
Otto

CleanShot 2025-09-26 at 11.44.05.png
September 29, 2025 at 1:23 pm #17441144

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Thanks.

I managed to deploy the copy of your site locally.

I noted a warning message (check the screenshot attached):
"WPML Media is enabled but not effective. It requires WPML in order to work."

But WPML is active.

Do you also see it? Just checking if it's a problem of the migration or if it may be an issue.

Best Regards,
Otto

CleanShot 2025-09-29 at 10.19.54@2x.png
September 29, 2025 at 1:48 pm #17441338

Natalie Wood

No i don't have that message on my site.

Is it just because of the sitekey that you need to update. My sitekey won't work on your install

September 29, 2025 at 6:13 pm #17442100

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

I spent some time trying to reproduce the problem with no luck 🙁

I tried in the copy of your site, in the pages that you mentioned, and also tried in a fresh installation. I couldn't reproduce the problem.

I analyzed the code with the help of AI. According to it, these are the conditions to make it happen and how to mitigate it:

When can images get deleted?
Trigger: After translating with ATE and then visiting specific admin screens (notably Media → Library). WPML’s automatic-media handling runs a cleanup that removes “duplicated copied” attachment translations.
Deletion path: It deletes a translated attachment record and fires a delete_post hook; if “Delete translations when deleting a post” is enabled, WPML may cascade-delete the other attachment translations using wp_delete_post, which for attachments calls wp_delete_attachment and removes the physical file.

Required conditions for deletion
WPML 4.8+ automatic media handling is enabled.
The attachment exists as translations (same TRID) across languages.
The attachment is classified as copied for the source post (in copied_media_ids); referenced media are not targeted.
Image texts are identical across languages: alt (wp_attachment_image_alt), caption (post_excerpt), and description (post_content). If they match exactly, the non-default-language translation is considered a duplicate and is deleted.
The global setting “Delete translations when deleting a post” is enabled (this enables the cascade that can lead to physical file deletion).
The cleanup is actually triggered (e.g., by opening Media → Library or the WPML media screen).

Not deleted if:
Automatic media handling is disabled.
The image is only referenced (not copied) in the post.
Any of alt/caption/description differ between languages.
“Delete translations when deleting a post” is disabled (then no cascade to wp_delete_attachment).
Why it can feel random
The cleanup runs on certain admin screens, not immediately after translation.
Whether an image is classified as copied vs referenced can vary with small content changes or how the block stores media.
ATE may sometimes set texts differently, breaking the “identical texts” condition.

I tried these conditions without luck, and you also tried disabling automatic media handling, so I have doubts about its accuracy.

Does this point you to any pattern that may help us find clear steps to reproduce the problem?

Best Regards,
Otto