Skip Navigation

Open

Reported for: WPML Media Translation 2.7.0

Topic Tags: Media Translation

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.

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>