technician_id()); $tech_name = $tech ? $tech->display_name : '#' . $session->technician_id(); $lines = []; $lines[] = '# Site Healthcheck — ' . $session->site_url(); $lines[] = ''; $lines[] = '- **Started:** ' . date('Y-m-d H:i', $session->started_at()); if ($session->is_finished()) { $lines[] = '- **Finished:** ' . date('Y-m-d H:i', (int) $session->finished_at()); $minutes = max(1, (int) round(((int) $session->finished_at() - $session->started_at()) / 60)); $lines[] = '- **Duration:** ~' . $minutes . ' minute(s)'; } $lines[] = '- **Technician:** ' . $tech_name; $lines[] = '- **Site:** ' . $session->site_url(); $lines[] = '- **WordPress:** ' . $session->wp_version(); $lines[] = '- **PHP:** ' . $session->php_version(); $lines[] = '- **Session ID:** ' . $session->id(); $lines[] = ''; // Summary table $lines[] = '## Summary'; $lines[] = ''; $lines[] = '| Step | Status |'; $lines[] = '|---|---|'; foreach (WPH_Steps::instance()->all() as $step) { $state = $session->step_state($step->id()); $lines[] = '| ' . $step->title() . ' | ' . wph_status_label($state['status']) . ' |'; } $lines[] = ''; // Per-step detail $lines[] = '## Detail'; $lines[] = ''; foreach (WPH_Steps::instance()->all() as $step) { $state = $session->step_state($step->id()); $lines[] = '### ' . $step->title(); $lines[] = ''; $lines[] = '_Status: ' . wph_status_label($state['status']) . '_'; if ($state['updated_at']) { $lines[] = '_Saved: ' . date('Y-m-d H:i', $state['updated_at']) . '_'; } if ($blurb = $step->blurb()) { $lines[] = ''; $lines[] = $blurb; } if ($items = $step->sub_items()) { $lines[] = ''; foreach ($items as $item) { $lines[] = '- [ ] ' . $item; } } if (!empty($state['notes'])) { $lines[] = ''; $lines[] = '**Notes:**'; $lines[] = ''; foreach (preg_split('/\R/', (string) $state['notes']) as $nl) { $lines[] = '> ' . $nl; } } $auto = $session->get_autocheck($step->id()); if ($auto && !empty($auto['findings'])) { $lines[] = ''; $lines[] = '**Automated checks** (run ' . date('Y-m-d H:i', (int) ($auto['checked_at'] ?? 0)) . '):'; $lines[] = ''; foreach ($auto['findings'] as $finding) { $icon = ['ok' => '✅', 'warn' => '⚠️', 'bad' => '❌', 'info' => 'ℹ️'][$finding['level']] ?? '·'; $bits = [$icon, '**' . $finding['label'] . '**']; if (!empty($finding['value'])) $bits[] = $finding['value']; if (!empty($finding['detail'])) $bits[] = '— ' . $finding['detail']; $lines[] = '- ' . implode(' ', $bits); } } if ($state['status'] === WPH_Session::STATUS_BLOCKED && ($esc = $step->escalation())) { $lines[] = ''; $lines[] = '> ⚠ **Escalation:** ' . $esc; } $lines[] = ''; } $lines[] = '---'; $lines[] = '_Generated by Site Healthcheck plugin v' . WPH_VERSION . '_'; return implode("\n", $lines) . "\n"; } function wph_build_html_report(WPH_Session $session): string { $tech = get_userdata($session->technician_id()); $tech_name = $tech ? $tech->display_name : '#' . $session->technician_id(); ob_start(); ?>
| Started | started_at())); ?> |
|---|---|
| Finished | finished_at())); ?> (≈ min) |
| Technician | |
| WordPress | wp_version()); ?> |
| PHP | php_version()); ?> |
| Step | Status |
|---|---|
| title()); ?> |
blurb()): ?> sub_items()): ?>