-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
Summary
When a Radio field has save_other_choice enabled, update_value() can emit PHP warnings if the field is JSON-only (no DB ID) or missing identifiers.
Affected area
includes/fields/class-acf-field-radio.php- Method:
acf_field_radio::update_value()
Problem
Current logic assumes the field always has an ID/key and that acf_get_field() returns a valid array with ID. In JSON/local-field scenarios, that may not be true, which can produce warnings (undefined array key / invalid array offset access).
Steps to reproduce
- Create a Radio field with
save_other_choice = 1. - Use a JSON/local field config (or a field array without persisted DB
ID). - Save a custom value not present in
choices. - Observe PHP warnings during
update_value().
Expected behavior
No warnings should be emitted. Value should still be returned/saved, and save-other-choice should only run when a valid persisted field is resolvable.
Proposed fix
- Build selector defensively:
- use
IDif available - else use
keyif available - bail if both are missing
- use
- Bail if
acf_get_field()returns non-array or noID - Ensure
choicesis an array before appending custom values
Tests
Add regression tests in:
tests/php/includes/fields/test-class-acf-field-radio.php
test_update_value_save_other_choice_handles_json_field_without_idtest_update_value_save_other_choice_handles_missing_field_identifier
Patch reference
Ready in commit: 94d21e5
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.