Uncaught Error: Call to undefined method stdClass::format_value_for_rest()
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Xác định điểm vào acf_format_value_for_rest() và kiểm tra cách sử dụng kết quả của acf_get_field_type() trước khi gọi format_value_for_rest(). Tái hiện lỗi phương thức không được định nghĩa với một kiểu trường không có phương thức này, sau đó bổ sung coverage cho thấy giá trị REST được xử lý mà không có lỗi không được bắt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 );
}
- Ngôn ngữ chính
- PHP
- Star
- 947
- Fork
- 198
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của AdvancedCustomFields/acf
-
PHP 8.5: "Using null as an array offset" deprecation in ACF_Data::is() when rendering a block with empty data (local-meta.php is_request)Có thể đã có người làm @faisalahammad đã nhận 17 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
AdvancedCustomFields/acf#1044 ·
-
is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)Có thể đã có người làm @faisalahammad đã nhận 17 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1041 · 1 bình luận ·
-
True / False ACF control bug on RTL layoutsCó thể đã có người làm @elicohenator đã nhận 39 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
AdvancedCustomFields/acf#1038 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1034 · 3 bình luận ·
-
Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+Có thể đã có người làm @antwonw đã nhận 51 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
AdvancedCustomFields/acf#1032 · 1 bình luận ·
Tất cả issue của AdvancedCustomFields/acf
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
wp-graphql/wp-graphql-woocommerce#1026 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
taskforcesh/bullmq#5038 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ServiceMapMissingAnalyser reads @method in docblock prose as a tag and reports a phantom accessorĐang mởagent-ready area:static-analysis bug p3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
gacela-project/gacela#1050 ·
Maintainer thường phản hồi trong vòng 1 ngày