WordPress / WordPress/secure-custom-fields

Radio save_other_choice triggers warnings for JSON-only or unidentified fields

Open
#381 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

[Type] Bug
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

  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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.