- ステータス
- 解決済み
- 報告対象
- WPML Media Translation 2.7.4
- 解決されたバージョン
- WPML 4.7.2
- トピックタグ
- Bug
問題の概要
WPML Media Translationプラグインを使用している場合、WordPressのスケーリングをトリガーする特大サイズの画像が翻訳され、その後その翻訳の1つが削除されると、問題が発生する場合があります。その結果、元の画像ファイルも削除され、元の言語で画像のリンク切れが発生します。
回避策
続行する前に、必ずサイトの完全なバックアップを取得してください。
- …/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; }