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
ID if available
- else use
key if available
- bail if both are missing
- Bail if
acf_get_field() returns non-array or no ID
- Ensure
choices is 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_id
test_update_value_save_other_choice_handles_missing_field_identifier
Patch reference
Ready in commit: 94d21e5
Summary
When a Radio field has
save_other_choiceenabled,update_value()can emit PHP warnings if the field is JSON-only (no DBID) or missing identifiers.Affected area
includes/fields/class-acf-field-radio.phpacf_field_radio::update_value()Problem
Current logic assumes the field always has an
ID/keyand thatacf_get_field()returns a valid array withID. In JSON/local-field scenarios, that may not be true, which can produce warnings (undefined array key / invalid array offset access).Steps to reproduce
save_other_choice = 1.ID).choices.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
IDif availablekeyif availableacf_get_field()returns non-array or noIDchoicesis an array before appending custom valuesTests
Add regression tests in:
tests/php/includes/fields/test-class-acf-field-radio.phptest_update_value_save_other_choice_handles_json_field_without_idtest_update_value_save_other_choice_handles_missing_field_identifierPatch reference
Ready in commit:
94d21e5