
內容簡介
Post Media Cleanup 外掛能在永久刪除文章時,自動清除伺服器上孤立的媒體檔案,確保媒體庫的整潔,避免不必要的檔案佔用空間。
【主要功能】
• 自動刪除孤立媒體檔案
• 僅在永久刪除時運作
• 支援多種文章類型配置
• 避免刪除共享媒體檔案
• 兼容 S3 和雲端儲存
• 開發者友好,提供過濾鉤子
外掛標籤
開發者團隊
原文外掛簡介
Post Media Cleanup removes orphaned media files from your server when you permanently delete a post.
When you permanently delete a post, this plugin automatically finds and removes:
Featured image
Images and files embedded in post content
PDFs and any linked files in content
All attachments uploaded directly to the post
Key Features
Only fires on permanent deletion — moving to trash is always safe
Skip Shared Media — never deletes a file used by another post
Works per post type — configure exactly which types trigger cleanup
Compatible with S3 and cloud storage
Multisite ready
Developer friendly — filter hooks to extend behaviour
For Developers
Add extra attachments to the deletion list:
add_filter( 'postmediaweb_attachment_ids_to_delete', function( $ids, $post_id ) {
$extra = get_post_meta( $post_id, 'my_custom_pdf', true );
if ( $extra ) $ids[] = (int) $extra;
return $ids;
}, 10, 2 );
Prevent a specific attachment from being deleted:
add_filter( 'postmediaweb_should_delete_attachment', function( $should, $att_id, $post_id ) {
if ( $att_id === 999 ) return false;
return $should;
}, 10, 3 );
