- 状态
- 已解决
- 报告针对
- WPML Media Translation 2.7.4
- 解决于
- WPML 4.7.2
- 主题标签
- Bug
问题概述
如果您使用的是 WPML Media Translation 插件,当翻译了触发 WordPress 缩放的超大图像,随后又删除了其中一个翻译时,您可能会遇到问题。结果会导致原始图像文件也被删除,并且原始语言中会出现损坏的图像链接。
临时解决方法
在继续操作之前,请确保对您的站点进行了完整的站点备份。
- 打开 …/wp-content/plugins/sitepress-multilingual-cms/classes/media/class-wpml-attachment-action.php 文件。
- 找到第 171 行。
- 将:
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; } - 替换为:
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; }