test: add regression coverage for Media pod REST save - #7594
Open
faisalahammad wants to merge 1 commit into
Open
test: add regression coverage for Media pod REST save#7594faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
faisalahammad
requested review from
JoryHogeveen and
sc0ttkclark
as code owners
August 9, 2026 16:28
Contributor
Author
|
AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me. |
Locks in the fix for pods-framework#6420. PodsRESTFields::register() maps the 'media' pod to the 'attachment' object type, so PodsRESTHandlers::save_handler() must look up $wp_rest_additional_fields by object type rather than by pod name. Reverting that lookup to the pod name leaves the array empty and this test fails, so it is a real guard rather than a restatement. Refs pods-framework#6420
faisalahammad
force-pushed
the
fix/6420-media-pod-rest-save
branch
from
August 19, 2026 18:06
066a891 to
8a0699e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a regression test for the Media pod REST save path. A Pods custom field added to the Media (attachment) pod could be read via the WP REST API but could not be written: a
POSTto/wp/v2/media/<id>returned the field as[false]and the value never persisted. The same field worked on a custom post type.Root cause was a lookup key mismatch in
PodsRESTHandlers::save_handler().register_rest_field( 'attachment', ... )stores the field under theattachmentkey in the$wp_rest_additional_fieldsglobal, but the handler was keying by the pod namemedia, so the field was never matched during the save loop. The fix keying the lookup by the WP post type is already present inclasses/PodsRESTHandlers.php.The new test directly invokes
save_handler()on a media pod and asserts the field is persisted. It fails if the lookup regresses to the pod name, locking the fix in place. No production code changes in this PR.Related GitHub issue(s)
Fixes #6420
Testing instructions
./vendor/bin/codecept run wpunit --group=pods-rest(covered by the existingwpunitmatrix entry in.github/workflows/tests-php.yml).$type-vs-$pod_namelookup inPodsRESTHandlers::save_handler()(change$wp_rest_additional_fields[ $type ]back to$wp_rest_additional_fields[ $pod_name ]on lines 287 and 297) and re-run.should_save_field_on_media_pod_via_save_handlerfails with'' != '42'. Restore the lookup to re-green.Screenshots / screencast
None. No UI changes.
Changelog text for these changes
Bug: A Pods custom field on the Media (attachment) pod can now be updated via the WP REST API. #6420 (@faisalahammad)
PR checklist