| @@ -42,8 +42,25 @@ | ||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | add_action('init', 'metasync_media_optimization_init'); |
| 45 | 45 | |
| 46 | +// Clean up converted sibling files (.webp/.avif) when an attachment is deleted. | |
| 47 | +// Registered unconditionally so orphaned files are removed even if conversion | |
| 48 | +// has since been disabled in settings. | |
| 49 | +add_action('delete_attachment', ['Metasync_Image_Converter', 'cleanup_on_delete']); | |
| 50 | + | |
| 51 | +// Drop cached media-library stats when an attachment is deleted so the | |
| 52 | +// admin stats card never counts removed images. | |
| 53 | +add_action('delete_attachment', ['Metasync_Media_Batch_Optimizer', 'flush_stats_cache']); | |
| 54 | + | |
| 55 | +// Invalidate cached image dimensions when an attachment is deleted or its | |
| 56 | +// metadata is (re)generated, so stale width/height are never injected after an | |
| 57 | +// image is removed, replaced under the same filename, or its thumbnails are | |
| 58 | +// regenerated to new sizes. Registered unconditionally so the cache cannot | |
| 59 | +// outlive the image even when dimension injection is disabled. | |
| 60 | +add_action('delete_attachment', ['Metasync_Dimension_Injector', 'purge_attachment_cache']); | |
| 61 | +add_filter('wp_update_attachment_metadata', ['Metasync_Dimension_Injector', 'purge_on_metadata_update'], 10, 2); | |
| 62 | + | |
| 46 | 63 | /** |
| 47 | 64 | * Enqueue media optimization admin assets on the correct page only. |
| 48 | 65 | * |
| 49 | 66 | * @param string $hook_suffix The current admin page hook suffix. |
| @@ -103,8 +120,9 @@ | ||
| 103 | 120 | 'revertFailed' => __('Revert failed.', 'metasync'), |
| 104 | 121 | 'revertDisabled' => __('Original image unavailable — revert is disabled', 'metasync'), |
| 105 | 122 | 'startBatch' => __('Start optimizing all unoptimized images?', 'metasync'), |
| 106 | 123 | 'batchFailed' => __('Failed to start batch optimization.', 'metasync'), |
| 124 | + 'batchStalled' => __('Batch optimization stopped after repeated errors. Please reload the page and try again.', 'metasync'), | |
| 107 | 125 | 'batchComplete' => __('Batch optimization complete!', 'metasync'), |
| 108 | 126 | 'imagesProcessed' => __('images processed', 'metasync'), |
| 109 | 127 | 'failed' => __('failed', 'metasync'), |
| 110 | 128 | 'optimizingOf' => __('Optimizing', 'metasync'), |
| @@ -117,8 +135,10 @@ | ||
| 117 | 135 | 'unoptimizing' => __('Unoptimizing...', 'metasync'), |
| 118 | 136 | 'unoptimizeConfirm' => __('Revert selected images to their original format?', 'metasync'), |
| 119 | 137 | 'bulkUnoptimizeFailed' => __('Bulk unoptimize failed.', 'metasync'), |
| 120 | 138 | 'alreadyUnoptimized' => __('All selected images are already unoptimized.', 'metasync'), |
| 139 | + 'deleteOrphanConfirm' => __('The file for this image is missing on disk. Delete this orphaned media record? This cannot be undone.', 'metasync'), | |
| 140 | + 'deleteOrphanFailed' => __('Failed to delete the orphaned media record.', 'metasync'), | |
| 121 | 141 | ), |
| 122 | 142 | )); |
| 123 | 143 | } |
| 124 | 144 | add_action('admin_enqueue_scripts', 'metasync_media_optimization_enqueue_assets'); |