WordPress / WordPress/secure-custom-fields
Radio save_other_choice triggers warnings for JSON-only or unidentified fields
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 131
- Forks
- 64
- Avg merge
- 10m
- Merged PRs (30d)
- 1
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read includes/fields/class-acf-field-radio.php, especially acf_field_radio::update_value(), and run the radio field regression tests in tests/php/includes/fields/test-class-acf-field-radio.php. Confirm the two named cases produce no warnings, preserve the value, and only apply save_other_choice when a valid persisted field and choices array are available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100