Skip to content

Select/Checkbox save_custom/save_options triggers warnings for JSON-only or unidentified fields#383

Open
meravi wants to merge 2 commits intoWordPress:trunkfrom
meravi:fix/select-checkbox-save-options-guards
Open

Select/Checkbox save_custom/save_options triggers warnings for JSON-only or unidentified fields#383
meravi wants to merge 2 commits intoWordPress:trunkfrom
meravi:fix/select-checkbox-save-options-guards

Conversation

@meravi
Copy link

@meravi meravi commented Mar 10, 2026

Summary

When custom option saving is enabled, Select (save_options) and Checkbox (save_custom) can emit PHP warnings if the runtime field is JSON-only (no DB ID) or missing identifiers.

Affected areas

  • includes/fields/class-acf-field-select.php (acf_field_select::update_value)
  • includes/fields/class-acf-field-checkbox.php (acf_field_checkbox::update_value)

Problem

Current logic assumes a valid field identifier (ID or key) and a successful acf_get_field() lookup with a persisted ID. In JSON/local-field scenarios this may be false, which can lead to warnings (undefined array key / invalid array access) while trying to append custom choices.

Steps to reproduce

  1. Configure a Select field with save_options = 1 (or Checkbox with save_custom = 1).
  2. Use field data coming from JSON/local config (or with missing persisted ID).
  3. Save a custom value not present in choices.
  4. Observe warnings during update_value().

Expected behavior

No warnings should be emitted. Value should still be returned/saved, and custom-choice persistence should only run when a valid persisted field can be resolved.

Proposed fix

  • Resolve selector defensively (ID -> key -> bail).
  • Bail when lookup cannot run or acf_get_field() result is invalid/no ID.
  • Normalize choices to an array before appending custom values.

Tests

Added regression tests:

  • tests/php/includes/fields/test-class-acf-field-select.php
    • test_update_value_save_options_handles_json_field_without_id
    • test_update_value_save_options_handles_missing_field_identifier
  • tests/php/includes/fields/test-class-acf-field-checkbox.php
    • test_update_value_save_custom_handles_json_field_without_id
    • test_update_value_save_custom_handles_missing_field_identifier

Patch reference

Commit: 34cfcb7
Branch: fix/select-checkbox-save-options-guards

@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ravikhadka.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant