$results Per task. * @param bool $dry_run * @param int $duration_ms * @return array The stored entry. */ public static function record( string $trigger, array $results, bool $dry_run, int $duration_ms ): array { $tasks = []; $bytes_total = 0; $items_total = 0; foreach ( $results as $id => $result ) { $tasks[ $id ] = $result->to_array(); $bytes_total += $result->bytes; $items_total += $result->items; } $entry = [ 'time' => time(), 'trigger' => $trigger, 'dry_run' => $dry_run, 'tasks' => $tasks, 'bytes_total' => $bytes_total, 'items_total' => $items_total, 'duration_ms' => $duration_ms, ]; $journal = self::all(); array_unshift( $journal, $entry ); $journal = array_slice( $journal, 0, self::DEPTH ); update_option( self::OPTION, $journal, false ); return $entry; } /** * The most recent dry-run estimate of what could be reclaimed. * * This is what the activation prompt shows — an unactivated site journals * dry runs, so there is always a current figure to state without scanning * the disk again on an admin page load. */ public static function last_estimate_bytes(): int { foreach ( self::all() as $entry ) { if ( ! empty( $entry['dry_run'] ) ) { return (int) ( $entry['bytes_total'] ?? 0 ); } } return 0; } public static function reset(): void { delete_option( self::OPTION ); } }