Uncaught Error: Call to undefined method stdClass::format_value_for_rest()
まだ誰も着手していません。
評価
調査の方向性
acf_format_value_for_rest() のエントリーポイントを特定し、format_value_for_rest() が呼び出される前に acf_get_field_type() の結果がどのように使用されているかを確認します。そのメソッドを持たないフィールドタイプで未定義メソッドによる失敗を再現し、その後、REST 値がキャッチされないエラーなしで処理されることを示すカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
External plugin sometimes break the REST api because they don't implement format_value_for_rest. |
Now this is really their fault. But a simple solution is to a function exists check:
method_exists( $type, 'format_value_for_rest' )
/**
* Format a given field's value for output in the REST API.
*
* @param $value
* @param $post_id
* @param $field
* @param string $format 'light' for normal REST API formatting or 'standard' to apply ACF's normal field formatting.
* @return mixed
*/
function acf_format_value_for_rest( $value, $post_id, $field, $format = 'light' ) {
if ( $format === 'standard' && function_exists( 'acf_format_value' ) ) {
$value_formatted = acf_format_value( $value, $post_id, $field );
} else {
$type = acf_get_field_type( $field['type'] );
if ( method_exists( $type, 'format_value_for_rest' ) ) {
$value_formatted = $type->format_value_for_rest( $value, $post_id, $field );
} else {
// Handle the case if neither function nor method exists
$value_formatted = $value; // or set default/fallback
}
}
/**
* Filter the formatted value for a given field.
*
* @param mixed $value_formatted The formatted value.
* @param string|int $post_id The post ID of the current object.
* @param array $field The field array.
* @param mixed $value The raw/unformatted value.
* @param string $format The format applied to the field value.
*/
return apply_filters( 'acf/rest/format_value_for_rest', $value_formatted, $post_id, $field, $value, $format );
}
- 主要言語
- PHP
- スター
- 946
- フォーク
- 197
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
AdvancedCustomFields/acf のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1041 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
AdvancedCustomFields/acf#1038 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1034 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
AdvancedCustomFields/acf#1032 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1029 · コメント 1 件 ·
AdvancedCustomFields/acf の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
UX
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ProfessionalWiki/NeoWiki#1573 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
endoflife-date/endoflife.date#11194 ·
メンテナーはふだん 1 日以内に返信