Open
Reported for: WPML Media Translation 2.7.3
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; };