Skip Navigation

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:

  1. 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.

4 Responses to “All media is duplicated when a new language is added”

  1. 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

  2. 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

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>