WPML

Overview of the Issue

Even after disabling all the media options under How to handle media for new content at WPMLSettingsMedia Translation, your site’s media will still be duplicated when you add a new language.

Workaround

This issue is fixed. Updating to the latest version solves it on your site, so you only need this workaround if you can’t update yet.

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.

All known issues

Still Seeing This Issue?

If updating doesn’t fix it, ask a support question and we’ll look into it with you.