Open
Reported for: WPML Media Translation 2.7.4
Overview of the issue
If you are using WPML Media Translation plugin, you may encounter a problem when an oversized image that triggers WordPress scaling is translated and then one of the translations is removed. As result, the original image file is also deleted and there would be a broken image link in the original language.
Workaround
Please, make sure of having a full site backup of your site before proceeding.
- Open …/wp-content/plugins/sitepress-multilingual-cms/classes/media/class-wpml-attachment-action.php file.
- Look for line 171.
- Replace:
public function delete_file_filter( $file ) { if ( $file ) { $file_name = $this->get_file_name( $file ); $sql = "SELECT pm.meta_id, pm.post_id FROM {$this->wpdb->postmeta} AS pm WHERE pm.meta_value = %s AND pm.meta_key='_wp_attached_file'"; $attachment_prepared = $this->wpdb->prepare( $sql, [ $file_name ] ); $attachment = $this->wpdb->get_row( $attachment_prepared ); if ( ! empty( $attachment ) ) { $file = null; } } return $file; }
- With:
public function delete_file_filter( $file ) { if ( $file ) { $file_name = $this->get_file_name( $file ); $test = explode('.', $file_name); $sliced = array_slice($test, 0, -1); $scaled = implode('.', $sliced); $ext = '-scaled.'. end($test); $processed = $scaled.$ext; $sql = "SELECT pm.meta_id, pm.post_id FROM {$this->wpdb->postmeta} AS pm WHERE pm.meta_value = %s OR pm.meta_value = '$processed' AND pm.meta_key='_wp_attached_file'"; $attachment_prepared = $this->wpdb->prepare( $sql, [ $file_name ] ); $attachment = $this->wpdb->get_row( $attachment_prepared ); if ( ! empty( $attachment ) ) { $file = null; } } return $file; }