Skip to content

Radio save_other_choice triggers warnings for JSON-only or unidentified fields #381

@meravi

Description

@meravi

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

  1. Create a Radio field with save_other_choice = 1.
  2. Use a JSON/local field config (or a field array without persisted DB ID).
  3. Save a custom value not present in choices.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions