Skip to content

Clean up attachments from incomplete form uploads#7510

Open
pdclark wants to merge 1 commit into
pods-framework:mainfrom
pdclark:fix/cleanup-incomplete-form-uploads
Open

Clean up attachments from incomplete form uploads#7510
pdclark wants to merge 1 commit into
pods-framework:mainfrom
pdclark:fix/cleanup-incomplete-form-uploads

Conversation

@pdclark
Copy link
Copy Markdown
Collaborator

@pdclark pdclark commented Apr 5, 2026

Summary

  • Tags file field attachments with _pods_pending_form_upload post meta (timestamp) when uploaded via AJAX in Pods->form()
  • Removes the flag when the form is successfully saved via PodsField_File::save()
  • Adds a daily WP-Cron job that deletes flagged attachments that are no longer pending
  • Skips attachments uploaded within the last 12 hours to allow time for forms still being filled out
  • Unschedules the cron on plugin deactivation

Fixes #7459

Test plan

  • Create a Pod with a File/Image/Video field and render with $pod->form()
  • Upload a file — verify _pods_pending_form_upload meta is set on the attachment
  • Submit the form — verify the meta is removed
  • Upload a file and abandon the form — verify meta persists
  • Trigger cron manually (do_action('pods_cleanup_pending_form_uploads')) with a backdated timestamp — verify the attachment is deleted
  • Verify attachments uploaded less than 12 hours ago are not deleted by the cron

@what-the-diff
Copy link
Copy Markdown

what-the-diff Bot commented Apr 5, 2026

PR Summary

  • Implemented Daily Cleanup for Unfinished Form Uploads
    We've added a new process that runs every day. This process will find and delete any form attachments that were uploaded but never used because the form wasn't completely filled out.

  • Deletion Logic for Aged Pending Attachments
    The daily process specifically locates and removes any attachments marked as "pending" that have been left unused for more than 12 hours. This keeps our system clean and more efficient.

  • Scheduled Cleanup Deactivated Along With Plugin
    When the Pods plugin is deactivated, this daily cleanup process is also halted. This ensures unnecessary tasks aren't running when they're not needed.

  • Marking Uploads for Future Removal
    Whenever a file is uploaded as a form attachment, it will initially be marked as "pending". Only when the form is successfully completed, this mark will be removed. This strategy enables the daily cleanup process to identify which of the attachments can be removed.

Tag file uploads with pending meta on AJAX upload, remove the flag
when the form is saved, and schedule a daily cron to delete attachments
that remain flagged and are older than 12 hours.

Fixes pods-framework#7459
@pdclark pdclark force-pushed the fix/cleanup-incomplete-form-uploads branch from 813b1d0 to e40872c Compare April 5, 2026 18:06
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.

Pods->form with file field can create orphan post

1 participant