Skip to content

fix: fall back to "All languages" value when ACF applied the field de… - #106

Open
lphoumpakka wants to merge 1 commit into
masterfrom
fix/default-value-fallback-acf-default
Open

lphoumpakka wants to merge 1 commit into
masterfrom
fix/default-value-fallback-acf-default

Conversation

@lphoumpakka

@lphoumpakka lphoumpakka commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

…fault

ACF replaces a missing value by the field default_value before acf/load_value. get_default_value() only fell back when the loaded value was null or '', so a true_false field with default_value 0 read as off in every language although enabled for "All languages".

Check whether a value is stored for the localized post id (raw metadata via acf_get_metadata_by_field(), or acf_get_metadata() on older ACF) and fall back when nothing is stored. A value saved for the language, even falsy, is kept; non-localized post ids keep the historical behaviour.

Add two tests and update CHANGELOG, README and TESTING counters.

This pull request fixes issue #{id}.

It will apply the following changes :


Note

Medium Risk
Changes front-end option loading for all localized ACF options pages when values are missing or falsy; behavior is covered by new tests but affects a core integration path.

Overview
Fixes multilingual ACF options incorrectly keeping the field default_value (e.g. true_false with default 0) instead of the All languages value when nothing is saved for the current language.

get_default_value() now decides whether to fall back by checking raw stored metadata for the localized options key via new has_stored_value() (acf_get_metadata_by_field() on ACF 6.4+, else acf_get_metadata()), not by treating the loaded $value as present. Explicitly saved falsy values for a language are still kept.

Adds two Test_Main cases and bumps documented test counts in CHANGELOG, README, and TESTING.

Reviewed by Cursor Bugbot for commit e3b9321. Bugbot is set up for automated code reviews on this repo. Configure here.

…fault

ACF replaces a missing value by the field default_value before acf/load_value.
get_default_value() only fell back when the loaded value was null or '', so a
true_false field with default_value 0 read as off in every language although
enabled for "All languages".

Check whether a value is stored for the localized post id (raw metadata via
acf_get_metadata_by_field(), or acf_get_metadata() on older ACF) and fall back
when nothing is stored. A value saved for the language, even falsy, is kept;
non-localized post ids keep the historical behaviour.

Add two tests and update CHANGELOG, README and TESTING counters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e3b9321. Configure here.

Comment thread classes/main.php
*
* @since 2.0.0
*/
$has_localized_value = $post_id === $original_post_id || $this->has_stored_value( $post_id, $field );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-option IDs skip stored-value check

Medium Severity

The new “has a stored localized value” gate is meant to leave non-localized post IDs on the old empty-value path, but it uses $post_id === $original_post_id. For numeric post IDs, original_option_id() returns 0 under Polylang, so that check never matches. get_default_value() still runs on any ACF AJAX request, so an unsaved post field whose value is only the field default_value is treated as missing and replaced via acf_get_value( 0, $field ).

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e3b9321. Configure here.

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