-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Description
概要
4.2.2 から 5.0.0 にアップデートした際、関連投稿 がFatalErrorで落ちてしまいました。
確認したところ 関連投稿 の対象となる post-type を指定していないとFatalになってしまうようでした。
詳細
下記のようなコードの場合にFatalになります。
$Setting->add_group(
'relation-without-post-type-string',
false,
array(
array(
'name' => 'text-has-default',
'label' => 'text has default',
'type' => 'relation',
'default' => 'a',
// 'post-type' => 'post' // この指定がなかった
),
)
);4.2.2では動いていたのですが、5.0.0で動かなくなった原因は、無指定だった場合に post の指定になるようになっていた箇所がなくなっていたためのようでした。
その上でエラーは implode に文字列が渡されていてFatalが起きていました。
エラーメッセージ
[20-Jun-2025 05:30:57 UTC] PHP Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in ... /wp-content/plugins/smart-custom-fields/classes/fields/class.field-related-posts.php:271
Stack trace:
#0 ...plugins/smart-custom-fields/classes/fields/class.field-related-posts.php(271): implode(',', '')
#1 .../wp-content/plugins/smart-custom-fields/classes/controller/class.controller-base.php(317): Smart_Custom_Fields_Field_Related_Posts->get_field(0, Array)
#2 .../wp-content/plugins/smart-custom-fields/classes/controller/class.controller-base.php(90): Smart_Custom_Fields_Controller_Base->display_tr(Object(WP_Post), false, Array, 0)
#3 .../wp/wp-admin/includes/template.php(1456): Smart_Custom_Fields_Controller_Base->display_meta_box(Object(WP_Post), Array)
#4 .../wp/wp-admin/includes/post.php(2394): do_meta_boxes(Object(WP_Screen), 'normal', Object(WP_Post))
#5 .../wp/wp-admin/edit-form-blocks.php(383): the_block_editor_meta_boxes()
#6 .../wp/wp-admin/post-new.php(72): require('/var/web/wp/wp-...')
#7 {main}
thrown in .../wp/wp-content/plugins/smart-custom-fields/classes/fields/class.field-related-posts.php on line 271
回避方法
回避方法を確認しました。
- add_group時に投稿タイプを指定する
post-typeがない場合にpostの指定になるようにする(4.2.2の状態に戻す)- options の
post-typeをarray()にする - implode の第二引数arrayにキャストする
質問
以上のような経緯でして add_group で投稿タイプを指定すれば問題は回避されそうなのですが、本体側での対応(上記の2~3のいずれか)はされますか?
Metadata
Metadata
Assignees
Labels
No labels