Add WebP conversion and garbage collection to MLS plugin

Image handling improvements:
- Convert PNG and images >500KB to WebP format
- Resize images wider than 1600px maintaining aspect ratio
- Check for .webp version before falling back to original
- WebP quality set to 80 (equivalent to JPEG 90%)

Garbage collection for disk space management:
- New MLS_Garbage_Collector class runs after each sync
- Only active when MLS_GC_DISK_THRESHOLD defined in wp-config
- Deletes image directories older than 24 hours, oldest first
- Stops when free space reaches 5GB or 2GB deleted per run
- Protects recently accessed images from deletion

Documentation:
- Added Garbage Collection section to README
- Updated Features list and File Structure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Hanson.xyz Dev
2026-01-04 20:48:57 -06:00
parent 25608a5327
commit c2d5b2248d
5 changed files with 777 additions and 20 deletions
@@ -512,6 +512,45 @@ class MLS_CLI {
if (!$result['success']) {
WP_CLI::halt(1);
}
// Run garbage collection after successful sync
if ($result['success']) {
$gc = $this->plugin->get_garbage_collector();
if ($gc && $gc->is_enabled()) {
if (!$silent) {
WP_CLI::line('');
WP_CLI::line('=== MLS Image Garbage Collection ===');
WP_CLI::line('');
}
$gc_result = $gc->run($status_callback);
if (!$silent && $gc_result['ran']) {
WP_CLI::line(sprintf(
'Deleted: %d directories (%s)',
$gc_result['deleted_count'],
$this->format_bytes($gc_result['deleted_bytes'])
));
}
}
}
}
/**
* Format bytes to human readable string
*
* @param int $bytes Bytes
* @return string Formatted string
*/
private function format_bytes($bytes) {
if ($bytes >= 1073741824) {
return number_format($bytes / 1073741824, 2) . ' GB';
} elseif ($bytes >= 1048576) {
return number_format($bytes / 1048576, 2) . ' MB';
} elseif ($bytes >= 1024) {
return number_format($bytes / 1024, 2) . ' KB';
}
return $bytes . ' bytes';
}
/**