Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Uncaught Error: Call to undefined method stdClass::format_value_for_rest()

オープン
#964 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
php
領域
api

調査の方向性

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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

AdvancedCustomFields/acf のほかの issue

AdvancedCustomFields/acf の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。