Repository navigation
fix: honor return_format in acf_format_value for Image/File fields - #530
faisalahammad wants to merge 1 commit into
Conversation
Fixes WordPress#527 Image and File fields ignored their Return format setting and always returned the raw attachment ID from get_field(). Add a safety net in acf_format_value(): when the acf/format_value filter chain leaves a numeric value unchanged but the field expects a formatted output, run the field type's format_value() directly so the configured return_format is honored. Add regression tests for the full acf_format_value() pipeline covering id, url, and array formats on both Image and File fields.
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jashick. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for the contribution and the effort here! 🙏 A heads-up on how this repo works: a large part of SCF's codebase (field types, Flexible Content, Blocks v3, local fields, forms, value formatting, and most of includes/ and assets/src/js/) is regularly synced from an upstream codebase. Any change we make there, whether a bug fix or a new feature, gets overwritten or causes hard merge conflicts on the next sync. That includes features behind a beta flag. Fixes for those areas arrive through the sync itself, so we can't accept PRs that touch that code, even good ones. |
Add a defensive fall-through in
acf_format_value(). When theacf/format_valuefilter chain leaves a numeric value unchanged but the field expects a formatted output (URL or array), the field type'sformat_value()runs directly so users see the configured return format instead of the raw attachment ID.Without this fix, Image and File fields return the attachment ID regardless of the
Return formatsetting.Closes #527
Use of AI Tools
This implementation was developed with the assistance of Claude Code (Anthropic) to help investigate the root cause and write the fix. The code and tests were reviewed and verified by the author.
Testing
composer test:php— 2880 tests / 21881 assertions, all greenvendor/bin/phpcs— no new errors (12 pre-existing unchanged)vendor/bin/phpstan includes/acf-value-functions.php— OKnpm run test:unit— 951 tests passingnpm run build— clean build