Skip Navigation

Open

Reported for: WPML Media Translation 2.7.3

Topic Tags: Bug

Overview of the issue

In WPML Media Translation, there’s a peculiar behavior where translating one image inadvertently applies the translation across all images that share a similar filename pattern. For instance, translating an image named img_file1.jpg also affects other images like img_file10.jpg or img_file11.jpg… despite them being distinct images.

The problem arises from the way Media Translation processes and replaces images based on filename patterns, leading to unintended replacements when filenames share a significant portion of their structure.

Workaround

Please, make sure of having a full backup of your site before proceeding.

  • Open …/wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-translated-images-update.php file.
  • Look for line 76.
  • Replace:
    		$media_src_contains_pre_update = function ( $media_src ) use ( $pre_update_translated_media_guid ) {
    			$thumb_file_name                   = basename( $pre_update_translated_media_guid );
    			$pre_update_translated_media_parts = explode( '.', $thumb_file_name );
    
    			$media_src_extension                   = pathinfo( $media_src, PATHINFO_EXTENSION );
    			$pre_update_translated_media_extension = is_array( $pre_update_translated_media_parts ) ? end( $pre_update_translated_media_parts ) : null;
    
    			return $pre_update_translated_media_parts[0] && false !== strpos( $media_src, $pre_update_translated_media_parts[0] ) && $media_src_extension === $pre_update_translated_media_extension;
    		};
    
  • With:
    		$media_src_contains_pre_update = function ( $media_src ) use ( $pre_update_translated_media_guid ) {
    			$thumb_file_name                   = basename( $pre_update_translated_media_guid );
    			$pre_update_translated_media_parts = explode( '.', $thumb_file_name );
    
    			$media_src_extension                   = pathinfo( $media_src, PATHINFO_EXTENSION );
    			$pre_update_translated_media_extension = is_array( $pre_update_translated_media_parts ) ? end( $pre_update_translated_media_parts ) : null;
    			$pattern = "/-d+xd+.".$pre_update_translated_media_parts[1]."$/";
    			$try = preg_replace($pattern, '.'. $pre_update_translated_media_parts[1], $media_src);
    			return $pre_update_translated_media_parts[0] && false !== str_contains( implode('.', $pre_update_translated_media_parts), $try ) && $media_src_extension === $pre_update_translated_media_extension;
    		};
    

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>