Skip to content

Conversation

@priethor
Copy link
Contributor

What

Closes #277

Image and File field types now respect the return_format field setting when returning values via the REST API.

Why

  • REST API always returned attachment IDs regardless of the return_format setting
  • Users expect consistent behavior between get_field() and REST API responses
  • The url and array return formats were broken for REST consumers

How

Modified format_value_for_rest() in both acf_field_image and acf_field_file to delegate to format_value() instead of calling acf_format_numerics()

Testing Instructions

  1. Create an Image or File field with return_format set to url or array
  2. Fetch a post with that field via REST API
  3. Verify the response matches the configured return format (URL string or attachment array)

@priethor priethor self-assigned this Dec 10, 2025
@priethor priethor added the [Type] Bug Something isn't working label Dec 10, 2025
@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 priethor.

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

@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 12.08%. Comparing base (5a894f5) to head (bd51a23).
⚠️ Report is 2 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #278      +/-   ##
============================================
+ Coverage     11.51%   12.08%   +0.56%     
  Complexity     4285     4285              
============================================
  Files           284      284              
  Lines         34697    34692       -5     
============================================
+ Hits           3996     4193     +197     
+ Misses        30701    30499     -202     
Flag Coverage Δ
e2e 30.68% <ø> (-0.03%) ⬇️
javascript 2.53% <ø> (ø)
phpunit 7.39% <100.00%> (+0.76%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where Image and File field types in the ACF plugin were ignoring the return_format setting when returning values via the REST API, always returning attachment IDs instead of respecting the configured format (url, array, or id).

Key Changes:

  • Modified format_value_for_rest() to delegate to format_value() instead of using acf_format_numerics()
  • Added comprehensive test coverage for both field types with all return format options
  • Enhanced documentation with version information and improved parameter descriptions

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
includes/fields/class-acf-field-image.php Updated format_value_for_rest() to respect return_format setting by delegating to format_value() method
includes/fields/class-acf-field-file.php Updated format_value_for_rest() to respect return_format setting by delegating to format_value() method
tests/php/includes/fields/test-class-acf-field-image.php Added comprehensive tests for image field REST formatting with all return format options (id, url, array)
tests/php/includes/fields/test-class-acf-field-file.php Added comprehensive tests for file field REST formatting with all return format options (id, url, array)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@WordPress WordPress deleted a comment from Copilot AI Dec 10, 2025
@WordPress WordPress deleted a comment from Copilot AI Dec 10, 2025
@WordPress WordPress deleted a comment from Copilot AI Dec 10, 2025
@priethor priethor merged commit d3bff0d into trunk Dec 10, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image and File fields ignore return_format setting in REST API

2 participants