| @@ -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. |
| @@ -100,10 +117,12 @@ | ||
| 100 | 117 | 'revert' => __('Revert', 'metasync'), |
| 101 | 118 | 'revertConfirm' => __('Revert this image to its original format?', 'metasync'), |
| 102 | 119 | 'optimizeFailed' => __('Optimization failed.', 'metasync'), |
| 103 | 120 | 'revertFailed' => __('Revert failed.', 'metasync'), |
| 121 | + 'revertDisabled' => __('Original image unavailable — revert is disabled', 'metasync'), | |
| 104 | 122 | 'startBatch' => __('Start optimizing all unoptimized images?', 'metasync'), |
| 105 | 123 | 'batchFailed' => __('Failed to start batch optimization.', 'metasync'), |
| 124 | + 'batchStalled' => __('Batch optimization stopped after repeated errors. Please reload the page and try again.', 'metasync'), | |
| 106 | 125 | 'batchComplete' => __('Batch optimization complete!', 'metasync'), |
| 107 | 126 | 'imagesProcessed' => __('images processed', 'metasync'), |
| 108 | 127 | 'failed' => __('failed', 'metasync'), |
| 109 | 128 | 'optimizingOf' => __('Optimizing', 'metasync'), |
| @@ -109,11 +128,17 @@ | ||
| 109 | 128 | 'optimizingOf' => __('Optimizing', 'metasync'), |
| 110 | 129 | 'of' => __('of', 'metasync'), |
| 111 | 130 | 'images' => __('images...', 'metasync'), |
| 112 | 131 | 'unoptimized' => __('Unoptimized', 'metasync'), |
| 113 | - 'selectImages' => __('Please select at least one image.', 'metasync'), | |
| 114 | - 'bulkFailed' => __('Bulk optimization failed.', 'metasync'), | |
| 115 | - 'apply' => __('Apply', 'metasync'), | |
| 132 | + 'selectImages' => __('Please select at least one image.', 'metasync'), | |
| 133 | + 'bulkFailed' => __('Bulk optimization failed.', 'metasync'), | |
| 134 | + 'apply' => __('Apply', 'metasync'), | |
| 135 | + 'unoptimizing' => __('Unoptimizing...', 'metasync'), | |
| 136 | + 'unoptimizeConfirm' => __('Revert selected images to their original format?', 'metasync'), | |
| 137 | + 'bulkUnoptimizeFailed' => __('Bulk unoptimize failed.', 'metasync'), | |
| 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'), | |
| 116 | 141 | ), |
| 117 | 142 | )); |
| 118 | 143 | } |
| 119 | 144 | add_action('admin_enqueue_scripts', 'metasync_media_optimization_enqueue_assets'); |