問題の概要
Advanced Custom Fieldsプラグインを使用している場合、以下の致命的なエラーが発生することがあります。このエラーは特にPHP 8以降で確認されています:
Fatal error: Uncaught TypeError: Illegal offset type in isset or empty in .../wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php:259
回避策
この問題はAdvanced Custom Fields Multilingual 2.1.0で修正されました。 更新するとサイト上の問題は解決するため、この回避策が必要になるのは、まだ更新できない場合のみです。
続行する前に、必ずサイトの完全なバックアップを取得してください。
- …/wp-content/plugins/acfml/classes/class-wpml-acf-attachments.php ファイルを開きます。
- 28行目を探します。
- 以下のコードを:
foreach ( $attachments as $key => $attachment_id ) { $translated_attachments[ $key ] = apply_filters( 'wpml_object_id', $attachment_id, 'attachment', true ); - 次のように置き換えます:
foreach ( $attachments as $key => $attachment_id ) { if (is_int($attachment_id)) { $translated_attachments[ $key ] = apply_filters( 'wpml_object_id', $attachment_id, 'attachment', true ); }