$size_data ) { if ( empty( $size_data['file'] ) ) { continue; } $size_path = trailingslashit( $dir ) . $size_data['file']; if ( ! is_readable( $size_path ) ) { continue; } self::process_single( (int) $attachment_id, (string) $size_key, $size_path ); // Refresh filesize in metadata after re-encode clearstatcache( true, $size_path ); $metadata['sizes'][ $size_key ]['filesize'] = filesize( $size_path ); } // Refresh full filesize too clearstatcache( true, $full_path ); $metadata['filesize'] = filesize( $full_path ); return $metadata; } private static function process_single( int $attachment_id, string $size_key, string $path ): void { $opt = Optimizer::optimise( $path ); // Generate WebP/AVIF siblings regardless of whether Optimizer touched // the source JPEG (e.g. it might have skipped tiny thumbnails). // Sibling generation is still valuable for those. $webp_stats = [ 'status' => 'skipped' ]; $avif_stats = [ 'status' => 'skipped' ]; $generate_siblings = in_array( $opt['status'], [ 'done', 'skipped' ], true ); if ( $generate_siblings && Settings::get( 'generate_webp', true ) ) { $webp_stats = Format_Generator::make_webp( $path ); } if ( $generate_siblings && Settings::get( 'generate_avif', true ) ) { $avif_stats = Format_Generator::make_avif( $path ); if ( $avif_stats['status'] === 'queued' ) { Attachment_Meta::mark_avif_pending( $attachment_id, $size_key ); } } Attachment_Meta::record_size( $attachment_id, $size_key, [ 'status' => $opt['status'], 'before' => $opt['before'], 'after' => $opt['after'], 'percent' => $opt['percent'], 'icc_preserved' => $opt['icc_preserved'] ?? false, 'tool_chain' => $opt['tool_chain'] ?? [], 'webp' => $webp_stats['status'] === 'done' ? $webp_stats['size'] : null, 'avif' => $avif_stats['status'] === 'done' ? $avif_stats['size'] : null, 'avif_status' => $avif_stats['status'], 'backup' => $opt['backup_path'] ?? null, 'error' => $opt['error'] ?? null, ] ); } }