Fix custom upload directory not applied during attachment import - #7598
Fix custom upload directory not applied during attachment import#7598faisalahammad wants to merge 2 commits into
Conversation
When a file field is configured to use a custom upload directory, files imported through pods_attachment_import() were still saved to the default wp-content/uploads/yyyy/mm path. This affected front-end imports such as the Gravity Forms integration and the Pods API save flow. Refactor the shared custom directory setup and teardown logic out of the AJAX upload path into reusable static helpers on PodsField_File, and have pods_attachment_import() honor the field's custom directory setting. The upload_dir filter stays active through attachment metadata generation so image sub-sizes also land in the custom directory, matching the AJAX path. Update the Pods API save path to pass the field and pod configuration so custom directory imports work for normal saves too. Fixes pods-framework#7393
|
AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me. |
Review: the tests are red, and half the fix is unreachableThree things to resolve before this can merge. 1. All three new tests fail as written
$scheme = wp_parse_url( $url, PHP_URL_SCHEME );
if ( ! in_array( $scheme, [ 'http', 'https' ], true ) ) { return ... 0; }
Either call 2. The
|
Description
When a File/Image/Video field is configured with "Upload Directory - Custom directory" and a custom path (for example
my-folder/another-folder/{@ID}), files uploaded through a front-end form were still saved to the defaultwp-content/uploads/yyyy/mmfolder.The custom upload directory logic only existed in the AJAX upload path (
PodsField_File::admin_ajax_upload()). Front-end imports such as the Gravity Forms integration and the Pods API save flow route throughpods_attachment_import(), which calledwp_upload_dir()without registering the custom directory filter, so imported files always landed in the default date-based folder.This change refactors the shared custom directory setup and teardown logic out of the AJAX path into reusable static helpers on
PodsField_File, then haspods_attachment_import()honor the field's custom directory setting. Theupload_dirfilter stays active through attachment metadata generation so image sub-sizes also land in the custom directory, matching the AJAX path. The Pods API save path now passes the field and pod configuration so the fix applies to normal saves too.Related GitHub issue(s)
Fixes #7393
Testing instructions
my-custom-dir/{@ID}.pods_form()or via the Pods API with a file value as a URL/GUID.wp-content/uploads/yyyy/mm, and that image sub-sizes (thumbnails) are also generated in the custom directory.Screenshots / screencast
Not applicable.
Changelog text for these changes
Bug: Files uploaded through a front-end form or the Pods API now respect a custom upload directory properly. #7393 (@faisalahammad)
PR checklist