Skip to content

WebP files are not deleted when attachment is deleted #10

@sun

Description

@sun

Problem

  • Website still consumes a very large amount of disk space after deleting media.

Cause

  • When deleting an attachment using WP-CLI (wp post delete --force 1234) then WordPress Core deletes its files from the uploads folder, but the webp files generated by Optimus remain in the filesystem.

Goal

  • Ensure webp derivatives are in sync with actual image attachments.
  • Free up disk space during cleanups to e.g. restart a site from scratch, or speed up website backup time.

Proposed solution

  1. React to the attachment delete hook.
  2. Check whether webp derivatives of registered image sizes exist in the filesystem.
  3. Delete the existing webp image files.

Notes

  • After fixing the basic integration behavior, a future PR could introduce a new WP-CLI command wp optimus webp delete-orphans similar to Feature request: add sync-missing command to wp client. #7 that allows to clean up an existing filesystem (i.e., considering all the sites that have obsolete webp image files currently).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions