Open
Reported for: WPML Media Translation 2.7.0
Overview of the issue
Even after disabling all the media options under How to handle media for new content at WPML → Settings → Media Translation, your site’s media will still be duplicated when you add a new language.
Workaround
Please make a full backup of your site before proceeding:
- Open the wp-content/plugins/sitepress-multilingual-cms/classes/media/Loader.php file.
Change from:
public static function getData() { return [ 'name' => 'media_setup', 'data' => [ 'endpoints' => [ 'prepareForTranslation' => PrepareForTranslation::class, 'translateExistingMedia' => TranslateExistingMedia::class, 'duplicateFeaturedImages' => DuplicateFeaturedImages::class, 'finishMediaTranslation' => FinishMediaTranslation::class, 'prepareForSetup' => PrepareSetup::class, 'performSetup' => PerformSetup::class, ] ] ]; } }
To:
public static function getData() { $media_handling = get_transient( 'media_handling' ); if ( ! $media_handling ) { $check = get_option( '_wpml_media' ); if ( $check["new_content_settings"]["duplicate_media"] ) { return [ 'name' => 'media_setup', 'data' => [ 'endpoints' => [ 'prepareForTranslation' => PrepareForTranslation::class, 'translateExistingMedia' => TranslateExistingMedia::class, 'duplicateFeaturedImages' => DuplicateFeaturedImages::class, 'finishMediaTranslation' => FinishMediaTranslation::class, 'prepareForSetup' => PrepareSetup::class, 'performSetup' => PerformSetup::class, ] ] ]; } set_transient('media_handling', true, DAY_IN_SECONDS); } else { return [ 'name' => 'media_setup', 'data' => [ 'endpoints' => [ 'prepareForTranslation' => PrepareForTranslation::class, 'duplicateFeaturedImages' => DuplicateFeaturedImages::class, 'finishMediaTranslation' => FinishMediaTranslation::class, 'prepareForSetup' => PrepareSetup::class, 'performSetup' => PerformSetup::class, ] ] ]; } } }
Please Note:
This code will not delete the duplicated images, it will just prevent the duplication process when creating a new language.
Hello,
Found this obviously after my website started duplicating thousands of images.
Now implemented the above fix, but is there anyway to automatically remove the duplicated images (and not the originals)? When doing this by hand it will take me ages, as over 100K images have been copied and re-uploaded to our media library..
Many thanks in advance.
Best,
Goort
Hello Goort,
WPML doesn’t bring a similar feature. However, you can consider using a tool like Media Cleaner.
Otherwise, please open a report in our forum.
Regards
What the hack. This is a brand new talk??`? hooo guys you are alive? And I found this and tried your code and nothing is working! As we don´t need the duplicates! Please deactivate and provide a working hook
I’m not sure to follow you. If you are encountering any issues with duplicated images, please open a chat in our support.