Phase 3 v2: all step automations + cross-cutting UI
Step automations (six more): - Step 3 (Core): current vs latest WP version, db upgrade flag, auto- update policy, safe-update sequence reminder. - Step 5 (Theme): parent/child detection, customisation warning when non-default theme without child, theme update available, inactive theme list. - Step 6 (Visual): mShots screenshot URL, key-page HEAD checks (home, login, posts page, WC shop/cart/checkout), mixed-content scan. - Step 7 (Performance): keyless PageSpeed Insights v5 API (mobile + desktop, cached 12h, skipped on .local), caching plugin detection, heavy-image scan (>500KB). - Step 10 (Uptime): monitoring plugin detection (ManageWP, MainWP, Jetpack, WP Umbrella, UptimeRobot), www/non-www canonical check. - Step 12 (Wrap-up): cross-step rollup — bad/warn counts, blocked steps, top examples for the technician's final glance. Cross-cutting: - Sticky step-index sidebar with status dots per step (the linear- stepper alternative that keeps the overview). - 'Stop & escalate' summary card at top listing blocked steps with escalation guidance and notes. - Previous-session snapshot stored on finish; diff banner on the next session shows new/resolved/changed counts. - HTML report builder (printable, inline-styled). Download HTML, Download Markdown, Copy, and Email actions on the finish panel. Email uses wp_mail with text/html. Smoke-tested on testsite: all 12 steps return findings (5/9/4 by level on a fresh local install), admin page renders with all UI markers, HTML report is 26KB, Markdown report is 13KB, prev-session diff banner appears on second session. Deferred: - hc-5ix.27 self-hosted update channel — needs hosting infra. - Full PDF report — would need vendoring Dompdf. - Step 3 safe-mode update wizard — worth its own bead.
This commit is contained in:
@@ -8,6 +8,8 @@ add_action('admin_post_wph_finish', 'wph_handle_finish');
|
||||
add_action('admin_post_wph_discard', 'wph_handle_discard');
|
||||
add_action('admin_post_wph_download_report', 'wph_handle_download_report');
|
||||
add_action('admin_post_wph_refresh_checks', 'wph_handle_refresh_checks');
|
||||
add_action('admin_post_wph_download_html', 'wph_handle_download_html');
|
||||
add_action('admin_post_wph_email_report', 'wph_handle_email_report');
|
||||
add_action('admin_enqueue_scripts', 'wph_enqueue_assets');
|
||||
|
||||
function wph_register_menu(): void {
|
||||
@@ -68,6 +70,24 @@ function wph_inline_css(): string {
|
||||
.wph-autocheck .value { color:#1d1d1f; }
|
||||
.wph-autocheck .detail { color:#646970; font-size:.9em; }
|
||||
.wph-checked-at { color:#646970; font-size:.85em; }
|
||||
.wph-layout { display:grid; grid-template-columns: 220px 1fr; gap:1rem; }
|
||||
.wph-sidebar { position:sticky; top:36px; align-self:start; max-height: calc(100vh - 60px); overflow:auto; }
|
||||
.wph-sidebar .wph-card { padding:.75rem 1rem; }
|
||||
.wph-sidebar h3 { margin:0 0 .4rem; font-size:.9rem; text-transform:uppercase; letter-spacing:.04em; color:#646970; }
|
||||
.wph-sidebar ol { margin:0; padding:0; list-style:none; }
|
||||
.wph-sidebar li { padding:.18rem 0; }
|
||||
.wph-sidebar a { text-decoration:none; }
|
||||
.wph-sidebar .dot { display:inline-block; width:.6rem; height:.6rem; border-radius:50%; margin-right:.4rem; background:#dcdcde; vertical-align:middle; }
|
||||
.wph-sidebar .dot-done { background:#1a8917; }
|
||||
.wph-sidebar .dot-skipped { background:#b07a00; }
|
||||
.wph-sidebar .dot-blocked { background:#c0392b; }
|
||||
.wph-sidebar .dot-n_a { background:#646970; }
|
||||
.wph-diff { background:#eef4fb; border:1px solid #cfe0f3; padding:.6rem 1rem; border-radius:6px; margin:.5rem 0; font-size:.9em; }
|
||||
.wph-diff strong { display:inline-block; margin-right:.4rem; }
|
||||
.wph-diff .delta-new { color:#c0392b; }
|
||||
.wph-diff .delta-resolved { color:#1a8917; }
|
||||
.wph-diff .delta-changed { color:#b07a00; }
|
||||
@media (max-width: 980px) { .wph-layout { grid-template-columns: 1fr; } .wph-sidebar { position: static; max-height: none; } }
|
||||
';
|
||||
}
|
||||
|
||||
@@ -138,10 +158,96 @@ function wph_render_active_session(WPH_Session $session): void {
|
||||
<?php
|
||||
|
||||
WPH_Recovery_Bootstrap::render_status();
|
||||
wph_render_blocked_summary($session);
|
||||
wph_render_diff_summary($session);
|
||||
|
||||
echo '<div class="wph-layout">';
|
||||
wph_render_sidebar($session);
|
||||
echo '<div>';
|
||||
foreach (WPH_Steps::instance()->all() as $step) {
|
||||
wph_render_step_card($session, $step);
|
||||
}
|
||||
echo '</div></div>';
|
||||
}
|
||||
|
||||
function wph_render_sidebar(WPH_Session $session): void {
|
||||
echo '<aside class="wph-sidebar"><div class="wph-card"><h3>Steps</h3><ol>';
|
||||
foreach (WPH_Steps::instance()->all() as $step) {
|
||||
$state = $session->step_state($step->id());
|
||||
$cls = 'dot-' . $state['status'];
|
||||
printf(
|
||||
'<li><span class="dot %s"></span><a href="#step-%s">%s</a></li>',
|
||||
esc_attr($cls),
|
||||
esc_attr($step->id()),
|
||||
esc_html($step->title())
|
||||
);
|
||||
}
|
||||
echo '</ol></div></aside>';
|
||||
}
|
||||
|
||||
function wph_render_blocked_summary(WPH_Session $session): void {
|
||||
$blocked = [];
|
||||
foreach (WPH_Steps::instance()->all() as $step) {
|
||||
$state = $session->step_state($step->id());
|
||||
if ($state['status'] === WPH_Session::STATUS_BLOCKED) {
|
||||
$blocked[] = ['step' => $step, 'state' => $state];
|
||||
}
|
||||
}
|
||||
if (!$blocked) return;
|
||||
echo '<div class="wph-card" style="border-left:4px solid #c0392b">';
|
||||
echo '<h2 style="color:#721c24">Stop & escalate</h2>';
|
||||
echo '<p>The following steps are blocked. Resolve or escalate before continuing:</p>';
|
||||
echo '<ul style="margin-left:1.25rem">';
|
||||
foreach ($blocked as $b) {
|
||||
$esc = $b['step']->escalation();
|
||||
echo '<li><a href="#step-' . esc_attr($b['step']->id()) . '"><strong>' . esc_html($b['step']->title()) . '</strong></a>';
|
||||
if ($esc) echo ' — ' . esc_html($esc);
|
||||
if (!empty($b['state']['notes'])) echo '<br><em>' . esc_html($b['state']['notes']) . '</em>';
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul></div>';
|
||||
}
|
||||
|
||||
function wph_render_diff_summary(WPH_Session $session): void {
|
||||
$prev = WPH_Session::previous();
|
||||
if (!$prev) return;
|
||||
|
||||
// Aggregate findings by step+id from each session
|
||||
$current_idx = [];
|
||||
foreach (WPH_Steps::instance()->all() as $step) {
|
||||
$r = $session->get_autocheck($step->id());
|
||||
if (!$r) continue;
|
||||
foreach ($r['findings'] as $f) {
|
||||
$current_idx[$step->id() . '|' . $f['id']] = $f;
|
||||
}
|
||||
}
|
||||
$prev_idx = [];
|
||||
foreach (WPH_Steps::instance()->all() as $step) {
|
||||
$r = $prev->get_autocheck($step->id());
|
||||
if (!$r) continue;
|
||||
foreach ($r['findings'] as $f) {
|
||||
$prev_idx[$step->id() . '|' . $f['id']] = $f;
|
||||
}
|
||||
}
|
||||
$new = $resolved = $changed = [];
|
||||
foreach ($current_idx as $k => $f) {
|
||||
if (!isset($prev_idx[$k])) {
|
||||
if (in_array($f['level'], ['warn', 'bad'], true)) $new[] = $f;
|
||||
} elseif ($prev_idx[$k]['level'] !== $f['level'] || $prev_idx[$k]['value'] !== $f['value']) {
|
||||
$changed[] = ['was' => $prev_idx[$k], 'now' => $f];
|
||||
}
|
||||
}
|
||||
foreach ($prev_idx as $k => $f) {
|
||||
if (!isset($current_idx[$k]) && in_array($f['level'], ['warn', 'bad'], true)) {
|
||||
$resolved[] = $f;
|
||||
}
|
||||
}
|
||||
if (!$new && !$resolved && !$changed) return;
|
||||
echo '<div class="wph-diff"><strong>Δ vs. previous session</strong> (finished ' . esc_html(date('Y-m-d', (int) $prev->finished_at())) . ')';
|
||||
if ($new) echo ' · <span class="delta-new">' . count($new) . ' new issue(s)</span>';
|
||||
if ($resolved) echo ' · <span class="delta-resolved">' . count($resolved) . ' resolved</span>';
|
||||
if ($changed) echo ' · <span class="delta-changed">' . count($changed) . ' changed</span>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function wph_render_step_card(WPH_Session $session, WPH_Step $step): void {
|
||||
@@ -207,21 +313,33 @@ function wph_render_step_card(WPH_Session $session, WPH_Step $step): void {
|
||||
|
||||
function wph_render_finished_panel(WPH_Session $session): void {
|
||||
$report = wph_build_markdown_report($session);
|
||||
$admin_email = get_option('admin_email');
|
||||
?>
|
||||
<div class="wph-card">
|
||||
<h2>Healthcheck finished</h2>
|
||||
<p>Started <?php echo esc_html(date('Y-m-d H:i', $session->started_at())); ?> · Finished <?php echo esc_html(date('Y-m-d H:i', (int) $session->finished_at())); ?></p>
|
||||
<div class="wph-actions">
|
||||
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
|
||||
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" style="display:inline">
|
||||
<?php wp_nonce_field('wph_download_report'); ?>
|
||||
<input type="hidden" name="action" value="wph_download_report">
|
||||
<button class="button button-primary">Download Markdown report</button>
|
||||
<button class="button button-primary">Download Markdown</button>
|
||||
</form>
|
||||
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" style="display:inline">
|
||||
<?php wp_nonce_field('wph_download_html'); ?>
|
||||
<input type="hidden" name="action" value="wph_download_html">
|
||||
<button class="button">Download HTML</button>
|
||||
</form>
|
||||
<button class="button" onclick="navigator.clipboard.writeText(document.getElementById('wph-report-md').textContent);this.textContent='Copied!';setTimeout(()=>this.textContent='Copy Markdown',2000)">Copy Markdown</button>
|
||||
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" style="display:inline">
|
||||
<?php wp_nonce_field('wph_email_report'); ?>
|
||||
<input type="hidden" name="action" value="wph_email_report">
|
||||
<input type="email" name="to" placeholder="recipient@example.com" value="<?php echo esc_attr($admin_email); ?>" required style="min-width:14em">
|
||||
<button class="button">Email report</button>
|
||||
</form>
|
||||
<button class="button" onclick="navigator.clipboard.writeText(document.getElementById('wph-report-md').textContent);this.textContent='Copied!';setTimeout(()=>this.textContent='Copy to clipboard',2000)">Copy to clipboard</button>
|
||||
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" onsubmit="return confirm('Discard this finished session?');" style="display:inline">
|
||||
<?php wp_nonce_field('wph_discard'); ?>
|
||||
<input type="hidden" name="action" value="wph_discard">
|
||||
<button class="button button-link-delete">Discard & start a new one</button>
|
||||
<button class="button button-link-delete">Discard</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -329,14 +447,45 @@ function wph_handle_download_report(): void {
|
||||
check_admin_referer('wph_download_report');
|
||||
$session = WPH_Session::current();
|
||||
if (!$session) wp_die('No session.');
|
||||
$report = wph_build_markdown_report($session);
|
||||
wph_stream_report($session, 'md');
|
||||
}
|
||||
|
||||
function wph_handle_download_html(): void {
|
||||
if (!current_user_can('manage_options')) wp_die('Forbidden');
|
||||
check_admin_referer('wph_download_html');
|
||||
$session = WPH_Session::current();
|
||||
if (!$session) wp_die('No session.');
|
||||
wph_stream_report($session, 'html');
|
||||
}
|
||||
|
||||
function wph_stream_report(WPH_Session $session, string $format): void {
|
||||
$host = parse_url(get_site_url(), PHP_URL_HOST) ?: 'site';
|
||||
$host = preg_replace('/[^a-z0-9.-]/i', '', (string) $host);
|
||||
$stamp = date('Ymd', $session->started_at() ?: time());
|
||||
$filename = 'wph-report-' . $host . '-' . $stamp . '.md';
|
||||
nocache_headers();
|
||||
header('Content-Type: text/markdown; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
echo $report;
|
||||
if ($format === 'html') {
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename="wph-report-' . $host . '-' . $stamp . '.html"');
|
||||
echo wph_build_html_report($session);
|
||||
} else {
|
||||
header('Content-Type: text/markdown; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename="wph-report-' . $host . '-' . $stamp . '.md"');
|
||||
echo wph_build_markdown_report($session);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function wph_handle_email_report(): void {
|
||||
if (!current_user_can('manage_options')) wp_die('Forbidden');
|
||||
check_admin_referer('wph_email_report');
|
||||
$session = WPH_Session::current();
|
||||
if (!$session) wp_die('No session.');
|
||||
$to = isset($_POST['to']) ? sanitize_email((string) wp_unslash($_POST['to'])) : '';
|
||||
if (!is_email($to)) wp_die('Bad email address.');
|
||||
$host = parse_url(get_site_url(), PHP_URL_HOST) ?: 'site';
|
||||
$subject = 'Site Healthcheck — ' . $host . ' — ' . date('Y-m-d', $session->started_at() ?: time());
|
||||
$html = wph_build_html_report($session);
|
||||
$ok = wp_mail($to, $subject, $html, ['Content-Type: text/html; charset=UTF-8']);
|
||||
wp_safe_redirect(admin_url('tools.php?page=site-healthcheck&wph_mail=' . ($ok ? '1' : '0')));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,13 @@ final class WPH_Session {
|
||||
delete_option(WPH_OPT_SESSION);
|
||||
}
|
||||
|
||||
/** The previous finished session (for diffing). Stored on finish(). */
|
||||
public static function previous(): ?self {
|
||||
$raw = get_option('wph_previous_session');
|
||||
if (!is_array($raw) || empty($raw['id'])) return null;
|
||||
return new self($raw);
|
||||
}
|
||||
|
||||
public function id(): string { return (string) $this->data['id']; }
|
||||
public function started_at(): int { return (int) $this->data['started_at']; }
|
||||
public function finished_at(): ?int { return isset($this->data['finished_at']) ? (int) $this->data['finished_at'] : null; }
|
||||
@@ -88,6 +95,8 @@ final class WPH_Session {
|
||||
public function finish(): void {
|
||||
$this->data['finished_at'] = time();
|
||||
update_option(WPH_OPT_SESSION, $this->data, false);
|
||||
// Snapshot for next-session diff. One slot, overwritten each finish.
|
||||
update_option('wph_previous_session', $this->data, false);
|
||||
}
|
||||
|
||||
/** Store the result of running autocheck() on a step. */
|
||||
|
||||
@@ -93,6 +93,115 @@ function wph_build_markdown_report(WPH_Session $session): string {
|
||||
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();
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Site Healthcheck — <?php echo esc_html($session->site_url()); ?></title>
|
||||
<style>
|
||||
body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #1d1d1f; background: #f7f7f8; margin: 0; padding: 2rem; }
|
||||
.wrap { max-width: 820px; margin: 0 auto; background: #fff; border-radius: 10px; padding: 2rem 2.4rem; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
|
||||
h1 { margin: 0 0 .25rem; font-size: 1.6rem; }
|
||||
h2 { margin: 1.5rem 0 .5rem; font-size: 1.15rem; border-bottom: 1px solid #e5e5ea; padding-bottom: .25rem; }
|
||||
h3 { margin: 1.2rem 0 .35rem; font-size: 1rem; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: .92em; margin: .4rem 0; }
|
||||
th, td { text-align: left; padding: .35rem .55rem; border-bottom: 1px solid #f0f0f1; vertical-align: top; }
|
||||
th { background: #fafafb; font-weight: 600; }
|
||||
.meta { color: #646970; }
|
||||
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
|
||||
.pill.done { background: #def7e3; color: #155724; }
|
||||
.pill.skipped { background: #fff3cd; color: #856404; }
|
||||
.pill.blocked { background: #fbeae8; color: #721c24; }
|
||||
.pill.n_a { background: #e2e3e5; color: #41464b; }
|
||||
.pill.not_started { background: #f0f0f1; color: #646970; }
|
||||
blockquote { margin: .5rem 0; padding: .35rem .9rem; border-left: 3px solid #c3c4c7; background: #fafafa; color: #444; }
|
||||
ul.findings { list-style: none; padding-left: 0; }
|
||||
ul.findings li { padding: .15rem 0; }
|
||||
.lvl-ok::before { content: '✓ '; color: #1a8917; font-weight: 700; }
|
||||
.lvl-warn::before { content: '⚠ '; color: #b07a00; font-weight: 700; }
|
||||
.lvl-bad::before { content: '✗ '; color: #c0392b; font-weight: 700; }
|
||||
.lvl-info::before { content: '· '; color: #646970; font-weight: 700; }
|
||||
.detail { color: #646970; font-size: .92em; }
|
||||
footer { margin-top: 2rem; color: #646970; font-size: .85em; text-align: center; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<h1>Site Healthcheck</h1>
|
||||
<p class="meta"><?php echo esc_html($session->site_url()); ?></p>
|
||||
|
||||
<table>
|
||||
<tr><th>Started</th><td><?php echo esc_html(date('Y-m-d H:i', $session->started_at())); ?></td></tr>
|
||||
<?php if ($session->is_finished()): $mins = max(1, (int) round(((int) $session->finished_at() - $session->started_at()) / 60)); ?>
|
||||
<tr><th>Finished</th><td><?php echo esc_html(date('Y-m-d H:i', (int) $session->finished_at())); ?> (≈<?php echo $mins; ?> min)</td></tr>
|
||||
<?php endif; ?>
|
||||
<tr><th>Technician</th><td><?php echo esc_html($tech_name); ?></td></tr>
|
||||
<tr><th>WordPress</th><td><?php echo esc_html($session->wp_version()); ?></td></tr>
|
||||
<tr><th>PHP</th><td><?php echo esc_html($session->php_version()); ?></td></tr>
|
||||
</table>
|
||||
|
||||
<h2>Summary</h2>
|
||||
<table>
|
||||
<thead><tr><th>Step</th><th>Status</th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach (WPH_Steps::instance()->all() as $step):
|
||||
$state = $session->step_state($step->id());
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo esc_html($step->title()); ?></td>
|
||||
<td><span class="pill <?php echo esc_attr($state['status']); ?>"><?php echo esc_html(str_replace('_', ' ', $state['status'])); ?></span></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2>Detail</h2>
|
||||
<?php foreach (WPH_Steps::instance()->all() as $step):
|
||||
$state = $session->step_state($step->id());
|
||||
$auto = $session->get_autocheck($step->id());
|
||||
?>
|
||||
<h3><?php echo esc_html($step->title()); ?></h3>
|
||||
<p><span class="pill <?php echo esc_attr($state['status']); ?>"><?php echo esc_html(str_replace('_', ' ', $state['status'])); ?></span></p>
|
||||
<?php if ($blurb = $step->blurb()): ?>
|
||||
<p><?php echo esc_html($blurb); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ($items = $step->sub_items()): ?>
|
||||
<ul>
|
||||
<?php foreach ($items as $i): ?>
|
||||
<li><?php echo esc_html($i); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($state['notes'])): ?>
|
||||
<blockquote><?php echo nl2br(esc_html($state['notes'])); ?></blockquote>
|
||||
<?php endif; ?>
|
||||
<?php if ($auto && !empty($auto['findings'])): ?>
|
||||
<ul class="findings">
|
||||
<?php foreach ($auto['findings'] as $f): ?>
|
||||
<li class="lvl-<?php echo esc_attr($f['level']); ?>">
|
||||
<strong><?php echo esc_html($f['label']); ?></strong>
|
||||
<?php if ($f['value'] !== ''): ?>— <?php echo esc_html($f['value']); ?><?php endif; ?>
|
||||
<?php if ($f['detail'] !== ''): ?><span class="detail"> — <?php echo esc_html($f['detail']); ?></span><?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<footer>Generated by Site Healthcheck plugin v<?php echo esc_html(WPH_VERSION); ?> · <?php echo esc_html(date('Y-m-d H:i')); ?></footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
|
||||
function wph_status_label(string $status): string {
|
||||
switch ($status) {
|
||||
case WPH_Session::STATUS_DONE: return '✅ Done';
|
||||
|
||||
@@ -10,4 +10,51 @@ return new class extends WPH_Step {
|
||||
'Confirm the site is resolving correctly on both www and non-www',
|
||||
];
|
||||
}
|
||||
|
||||
public function autocheck(array $session_state): array {
|
||||
$f = [];
|
||||
|
||||
// Known monitoring plugins
|
||||
$monitors = [
|
||||
'worker/init.php' => 'ManageWP Worker',
|
||||
'mainwp-child/mainwp-child.php' => 'MainWP Child',
|
||||
'jetpack/jetpack.php' => 'Jetpack',
|
||||
'wp-umbrella/wp-umbrella.php' => 'WP Umbrella',
|
||||
'uptime-robot/uptime-robot.php' => 'UptimeRobot',
|
||||
];
|
||||
$detected = [];
|
||||
foreach ($monitors as $file => $label) {
|
||||
if (function_exists('is_plugin_active') && is_plugin_active($file)) $detected[] = $label;
|
||||
}
|
||||
$f[] = $this->finding(
|
||||
'monitor_plugin',
|
||||
$detected ? 'ok' : 'info',
|
||||
'Monitoring plugin',
|
||||
$detected ? implode(', ', $detected) : 'none detected',
|
||||
$detected ? 'Pull downtime stats from the relevant dashboard.' : 'External monitoring (UptimeRobot/BetterStack/Pingdom) may still be in place.'
|
||||
);
|
||||
|
||||
// www vs non-www: try fetching both and see whether one redirects to the other
|
||||
$home = home_url('/');
|
||||
$parts = parse_url($home);
|
||||
$host = $parts['host'] ?? '';
|
||||
$scheme = $parts['scheme'] ?? 'https';
|
||||
if ($host) {
|
||||
$with_www = $scheme . '://' . (strpos($host, 'www.') === 0 ? $host : 'www.' . $host) . '/';
|
||||
$without_www = $scheme . '://' . preg_replace('/^www\./', '', $host) . '/';
|
||||
foreach (['with www' => $with_www, 'without www' => $without_www] as $label => $url) {
|
||||
$resp = wp_remote_head($url, ['timeout' => 5, 'redirection' => 0]);
|
||||
if (is_wp_error($resp)) {
|
||||
$f[] = $this->finding('canonical_' . sanitize_key($label), 'warn', $label, $url, $resp->get_error_message());
|
||||
continue;
|
||||
}
|
||||
$code = wp_remote_retrieve_response_code($resp);
|
||||
$loc = wp_remote_retrieve_header($resp, 'location');
|
||||
$detail = $loc ? '→ ' . $loc : '';
|
||||
$f[] = $this->finding('canonical_' . sanitize_key($label), 'info', $label, 'HTTP ' . $code, $detail);
|
||||
}
|
||||
}
|
||||
|
||||
return $f;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,4 +13,57 @@ return new class extends WPH_Step {
|
||||
'If anything was flagged that needs a separate quote or client decision, send that communication now rather than leaving it',
|
||||
];
|
||||
}
|
||||
|
||||
public function autocheck(array $session_state): array {
|
||||
// Roll up all 'bad' and 'warn' findings from other steps into a wrap-up summary.
|
||||
$bad = [];
|
||||
$warn = [];
|
||||
$blocked = [];
|
||||
foreach (WPH_Steps::instance()->all() as $sid => $s) {
|
||||
if ($sid === 'wrap_up') continue;
|
||||
// Pull stored autocheck results from session data (we get session_state passed in).
|
||||
$stored = $session_state['autocheck'][$sid] ?? null;
|
||||
if ($stored && !empty($stored['findings'])) {
|
||||
foreach ($stored['findings'] as $finding) {
|
||||
$label = $s->title() . ' → ' . $finding['label'];
|
||||
if ($finding['level'] === 'bad') $bad[] = $label . ' (' . $finding['value'] . ')';
|
||||
if ($finding['level'] === 'warn') $warn[] = $label . ' (' . $finding['value'] . ')';
|
||||
}
|
||||
}
|
||||
$step_state = $session_state['steps'][$sid] ?? null;
|
||||
if (is_array($step_state) && ($step_state['status'] ?? '') === 'blocked') {
|
||||
$blocked[] = $s->title();
|
||||
}
|
||||
}
|
||||
$f = [];
|
||||
$f[] = $this->finding(
|
||||
'bad_count',
|
||||
count($bad) > 0 ? 'bad' : 'ok',
|
||||
'Critical findings',
|
||||
(string) count($bad),
|
||||
$bad ? implode(' · ', array_slice($bad, 0, 6)) . (count($bad) > 6 ? ' …' : '') : 'No bad-level findings across steps.'
|
||||
);
|
||||
$f[] = $this->finding(
|
||||
'warn_count',
|
||||
count($warn) > 0 ? 'warn' : 'ok',
|
||||
'Warnings',
|
||||
(string) count($warn),
|
||||
$warn ? implode(' · ', array_slice($warn, 0, 8)) . (count($warn) > 8 ? ' …' : '') : ''
|
||||
);
|
||||
$f[] = $this->finding(
|
||||
'blocked_steps',
|
||||
count($blocked) > 0 ? 'bad' : 'ok',
|
||||
'Blocked steps',
|
||||
(string) count($blocked),
|
||||
$blocked ? implode(', ', $blocked) : ''
|
||||
);
|
||||
$f[] = $this->finding(
|
||||
'tip_copy',
|
||||
'info',
|
||||
'Tip',
|
||||
'paste this into the client record',
|
||||
'Click Copy to clipboard on the finish screen — the full Markdown report is also downloadable.'
|
||||
);
|
||||
return $f;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,4 +18,64 @@ return new class extends WPH_Step {
|
||||
'White screen of death post-update, admin redirect loops, missing admin menu items — these usually indicate a theme or plugin conflict with the new core version.',
|
||||
];
|
||||
}
|
||||
|
||||
public function autocheck(array $session_state): array {
|
||||
global $wp_version;
|
||||
$f = [];
|
||||
|
||||
if (!function_exists('get_core_updates')) require_once ABSPATH . 'wp-admin/includes/update.php';
|
||||
$updates = function_exists('get_core_updates') ? get_core_updates(['dismissed' => true]) : [];
|
||||
$latest = (!empty($updates) && !empty($updates[0]->current)) ? $updates[0]->current : $wp_version;
|
||||
$behind = version_compare($wp_version, $latest, '<');
|
||||
|
||||
$f[] = $this->finding(
|
||||
'wp_current',
|
||||
'info',
|
||||
'Currently installed',
|
||||
$wp_version,
|
||||
''
|
||||
);
|
||||
$f[] = $this->finding(
|
||||
'wp_latest',
|
||||
$behind ? 'warn' : 'ok',
|
||||
'Latest available',
|
||||
$latest,
|
||||
$behind ? 'Update available → ' . admin_url('update-core.php') : 'Up to date.'
|
||||
);
|
||||
|
||||
// Database upgrade required?
|
||||
if (function_exists('wp_get_db_schema')) {
|
||||
$required = (int) get_option('db_version');
|
||||
global $wp_db_version;
|
||||
if ($required > 0 && $wp_db_version > $required) {
|
||||
$f[] = $this->finding('db_upgrade', 'warn', 'Database upgrade', 'pending', 'WP code is at v' . $wp_db_version . ', database at v' . $required . '. Visit /wp-admin/upgrade.php.');
|
||||
} else {
|
||||
$f[] = $this->finding('db_upgrade', 'ok', 'Database upgrade', 'not needed', '');
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-updates configured?
|
||||
$core_auto = get_site_option('auto_update_core_major', null);
|
||||
if ($core_auto === null) $core_auto = defined('WP_AUTO_UPDATE_CORE') ? (string) WP_AUTO_UPDATE_CORE : 'minor';
|
||||
$f[] = $this->finding(
|
||||
'auto_update',
|
||||
'info',
|
||||
'Core auto-update policy',
|
||||
(string) $core_auto,
|
||||
'Configured via Updates → Auto-updates or the WP_AUTO_UPDATE_CORE constant.'
|
||||
);
|
||||
|
||||
// Safe-mode update guidance — not an action, just a reminder.
|
||||
if ($behind) {
|
||||
$f[] = $this->finding(
|
||||
'safe_mode_hint',
|
||||
'info',
|
||||
'Safe-update sequence',
|
||||
'see detail',
|
||||
'Deactivate non-essential plugins → run the update → smoke-load front-end + wp-admin → reactivate plugins.'
|
||||
);
|
||||
}
|
||||
|
||||
return $f;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,4 +17,82 @@ return new class extends WPH_Step {
|
||||
'Layout changes post-theme update, broken header/footer, missing custom fonts or colours — indicates customisation was done directly in the parent theme.',
|
||||
];
|
||||
}
|
||||
|
||||
public function autocheck(array $session_state): array {
|
||||
$f = [];
|
||||
$active = wp_get_theme();
|
||||
$is_child = (bool) $active->parent();
|
||||
$parent = $is_child ? $active->parent() : null;
|
||||
|
||||
$f[] = $this->finding(
|
||||
'active_theme',
|
||||
'info',
|
||||
'Active theme',
|
||||
(string) $active->get('Name') . ' v' . (string) $active->get('Version'),
|
||||
'Slug: ' . $active->get_stylesheet() . ($is_child ? ' (child of ' . $parent->get_stylesheet() . ')' : '')
|
||||
);
|
||||
|
||||
// Child theme practice: warn if active theme has been customised but isn't a child
|
||||
$is_default = preg_match('/^twenty/i', $active->get_stylesheet());
|
||||
if (!$is_child && !$is_default) {
|
||||
$style_mtime = file_exists($active->get_stylesheet_directory() . '/style.css')
|
||||
? filemtime($active->get_stylesheet_directory() . '/style.css')
|
||||
: 0;
|
||||
$functions_mtime = file_exists($active->get_stylesheet_directory() . '/functions.php')
|
||||
? filemtime($active->get_stylesheet_directory() . '/functions.php')
|
||||
: 0;
|
||||
$modified = max($style_mtime, $functions_mtime);
|
||||
$f[] = $this->finding(
|
||||
'no_child_theme',
|
||||
'warn',
|
||||
'Child theme practice',
|
||||
'no child theme',
|
||||
'Parent theme is being used directly. Last edit to style.css/functions.php: ' . ($modified ? date('Y-m-d', $modified) : 'unknown') . '. An update may overwrite customisations — confirm with client first.'
|
||||
);
|
||||
} else {
|
||||
$f[] = $this->finding(
|
||||
'child_theme_ok',
|
||||
'ok',
|
||||
'Child theme practice',
|
||||
$is_child ? 'using a child theme' : 'default theme — no customisation expected',
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
// Updates available
|
||||
if (!function_exists('wp_get_themes')) require_once ABSPATH . 'wp-includes/theme.php';
|
||||
if (function_exists('wp_update_themes')) wp_update_themes();
|
||||
$updates = get_site_transient('update_themes');
|
||||
$update_map = isset($updates->response) && is_array($updates->response) ? $updates->response : [];
|
||||
|
||||
if (isset($update_map[$active->get_stylesheet()])) {
|
||||
$new = $update_map[$active->get_stylesheet()]['new_version'] ?? '?';
|
||||
$f[] = $this->finding(
|
||||
'active_update',
|
||||
'warn',
|
||||
'Active theme update',
|
||||
'v' . $new . ' available',
|
||||
$is_child ? 'Safe to apply (child in use).' : 'Caution — may overwrite parent-theme customisations.'
|
||||
);
|
||||
} else {
|
||||
$f[] = $this->finding('active_update', 'ok', 'Active theme update', 'up to date', '');
|
||||
}
|
||||
|
||||
// Inactive themes
|
||||
$all = wp_get_themes();
|
||||
$inactive = [];
|
||||
foreach ($all as $slug => $t) {
|
||||
if ($slug === $active->get_stylesheet() || ($is_child && $slug === $parent->get_stylesheet())) continue;
|
||||
$inactive[$slug] = (string) $t->get('Name');
|
||||
}
|
||||
$f[] = $this->finding(
|
||||
'inactive_themes',
|
||||
count($inactive) > 3 ? 'warn' : 'info',
|
||||
'Inactive themes',
|
||||
(string) count($inactive),
|
||||
$inactive ? implode(', ', array_slice($inactive, 0, 6)) . (count($inactive) > 6 ? ' …' : '') : ''
|
||||
);
|
||||
|
||||
return $f;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,4 +20,70 @@ return new class extends WPH_Step {
|
||||
'Redirects — confirm www/non-www and HTTP/HTTPS are redirecting correctly to the canonical URL',
|
||||
];
|
||||
}
|
||||
|
||||
public function autocheck(array $session_state): array {
|
||||
$f = [];
|
||||
$home = home_url('/');
|
||||
|
||||
// mShots screenshot (WordPress.com's public screenshot service, no key needed)
|
||||
$shot = 'https://s.wordpress.com/mshots/v1/' . rawurlencode($home) . '?w=1200';
|
||||
$f[] = $this->finding(
|
||||
'screenshot',
|
||||
'info',
|
||||
'Homepage screenshot',
|
||||
$home,
|
||||
'mShots: ' . $shot . ' — open this URL to view the rendered preview.'
|
||||
);
|
||||
|
||||
// Key pages we should be able to find
|
||||
$pages = [
|
||||
'Home' => $home,
|
||||
'Login' => wp_login_url(),
|
||||
'Posts page' => function_exists('get_post_type_archive_link') ? get_post_type_archive_link('post') : '',
|
||||
];
|
||||
if (function_exists('get_option')) {
|
||||
$page_for_posts = (int) get_option('page_for_posts');
|
||||
if ($page_for_posts) $pages['Posts page'] = get_permalink($page_for_posts) ?: $pages['Posts page'];
|
||||
}
|
||||
// WooCommerce shop?
|
||||
if (class_exists('WooCommerce') && function_exists('wc_get_page_id')) {
|
||||
$shop_id = (int) wc_get_page_id('shop');
|
||||
if ($shop_id > 0) $pages['WC shop'] = get_permalink($shop_id);
|
||||
$cart_id = (int) wc_get_page_id('cart');
|
||||
if ($cart_id > 0) $pages['WC cart'] = get_permalink($cart_id);
|
||||
$checkout_id = (int) wc_get_page_id('checkout');
|
||||
if ($checkout_id > 0) $pages['WC checkout'] = get_permalink($checkout_id);
|
||||
}
|
||||
|
||||
foreach ($pages as $label => $url) {
|
||||
if (!$url) continue;
|
||||
$resp = wp_remote_head($url, ['timeout' => 5, 'redirection' => 3]);
|
||||
if (is_wp_error($resp)) {
|
||||
$f[] = $this->finding('page_' . sanitize_key($label), 'bad', $label, $url, $resp->get_error_message());
|
||||
continue;
|
||||
}
|
||||
$code = wp_remote_retrieve_response_code($resp);
|
||||
$level = ($code >= 200 && $code < 400) ? 'ok' : 'bad';
|
||||
$f[] = $this->finding('page_' . sanitize_key($label), $level, $label, 'HTTP ' . $code, $url);
|
||||
}
|
||||
|
||||
// Mixed content quick check on homepage
|
||||
if (parse_url($home, PHP_URL_SCHEME) === 'https') {
|
||||
$body_resp = wp_remote_get($home, ['timeout' => 6]);
|
||||
if (!is_wp_error($body_resp)) {
|
||||
$body = (string) wp_remote_retrieve_body($body_resp);
|
||||
preg_match_all('/(?:src|href)\s*=\s*["\']http:\/\/[^"\']+["\']/i', $body, $m);
|
||||
$http_count = isset($m[0]) ? count($m[0]) : 0;
|
||||
$f[] = $this->finding(
|
||||
'mixed_content',
|
||||
$http_count > 0 ? 'warn' : 'ok',
|
||||
'Mixed content',
|
||||
$http_count . ' http:// reference(s) on homepage',
|
||||
$http_count ? 'Browsers will block or warn — replace with https:// or protocol-relative URLs.' : ''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $f;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,4 +13,119 @@ return new class extends WPH_Step {
|
||||
'Check image sizes on the homepage — flag if uncompressed images over 500KB are being served',
|
||||
];
|
||||
}
|
||||
|
||||
public function autocheck(array $session_state): array {
|
||||
$f = [];
|
||||
$home = home_url('/');
|
||||
|
||||
// PageSpeed Insights — no API key needed for low volume (25k/day per IP).
|
||||
// Skip on localhost: PSI can't reach a local URL.
|
||||
$host = parse_url($home, PHP_URL_HOST) ?: '';
|
||||
$is_local = preg_match('/(\.local|localhost|^127\.|^192\.168\.)/', $host);
|
||||
|
||||
if ($is_local) {
|
||||
$f[] = $this->finding('psi_skipped', 'info', 'PageSpeed Insights', 'skipped (local host)', 'Run manually from a public URL: https://pagespeed.web.dev/');
|
||||
} else {
|
||||
foreach (['mobile', 'desktop'] as $strategy) {
|
||||
$psi = $this->psi($home, $strategy);
|
||||
if ($psi === null) {
|
||||
$f[] = $this->finding('psi_' . $strategy, 'warn', 'PageSpeed (' . $strategy . ')', 'API error', 'Could not reach googleapis.com — retry or run manually.');
|
||||
continue;
|
||||
}
|
||||
$score = (int) round((float) $psi['performance'] * 100);
|
||||
$level = $score >= 90 ? 'ok' : ($score >= 50 ? 'warn' : 'bad');
|
||||
$detail_bits = [];
|
||||
if (isset($psi['lcp'])) $detail_bits[] = 'LCP ' . $psi['lcp'];
|
||||
if (isset($psi['cls'])) $detail_bits[] = 'CLS ' . $psi['cls'];
|
||||
if (isset($psi['tbt'])) $detail_bits[] = 'TBT ' . $psi['tbt'];
|
||||
$f[] = $this->finding(
|
||||
'psi_' . $strategy,
|
||||
$level,
|
||||
'PageSpeed (' . $strategy . ')',
|
||||
$score . '/100',
|
||||
implode(' · ', $detail_bits)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Caching plugin detection
|
||||
$caching = [
|
||||
'wp-rocket/wp-rocket.php' => 'WP Rocket',
|
||||
'wp-super-cache/wp-cache.php' => 'WP Super Cache',
|
||||
'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache',
|
||||
'litespeed-cache/litespeed-cache.php' => 'LiteSpeed Cache',
|
||||
'sg-cachepress/sg-cachepress.php' => 'SG Optimizer',
|
||||
'wp-fastest-cache/wpFastestCache.php'=> 'WP Fastest Cache',
|
||||
'cache-enabler/cache-enabler.php' => 'Cache Enabler',
|
||||
];
|
||||
$found_caching = null;
|
||||
foreach ($caching as $file => $label) {
|
||||
if (is_plugin_active($file)) { $found_caching = $label; break; }
|
||||
}
|
||||
$f[] = $this->finding(
|
||||
'caching',
|
||||
$found_caching ? 'ok' : 'info',
|
||||
'Caching plugin',
|
||||
$found_caching ?: 'none detected',
|
||||
$found_caching ? '' : 'No common caching plugin active — host-level caching may still apply.'
|
||||
);
|
||||
|
||||
// Heavy images on the homepage
|
||||
$resp = wp_remote_get($home, ['timeout' => 6]);
|
||||
if (!is_wp_error($resp)) {
|
||||
$body = (string) wp_remote_retrieve_body($resp);
|
||||
preg_match_all('/<img\b[^>]*src=["\']([^"\']+)["\']/i', $body, $m);
|
||||
$urls = isset($m[1]) ? array_slice(array_unique($m[1]), 0, 8) : [];
|
||||
$heavy = [];
|
||||
foreach ($urls as $u) {
|
||||
if (substr($u, 0, 2) === '//') $u = (parse_url($home, PHP_URL_SCHEME) ?: 'https') . ':' . $u;
|
||||
if (substr($u, 0, 1) === '/') $u = rtrim($home, '/') . $u;
|
||||
$head = wp_remote_head($u, ['timeout' => 3, 'redirection' => 2]);
|
||||
if (is_wp_error($head)) continue;
|
||||
$size = (int) wp_remote_retrieve_header($head, 'content-length');
|
||||
if ($size > 500 * 1024) {
|
||||
$heavy[] = basename(parse_url($u, PHP_URL_PATH) ?: $u) . ' (' . size_format($size) . ')';
|
||||
}
|
||||
}
|
||||
$f[] = $this->finding(
|
||||
'heavy_images',
|
||||
$heavy ? 'warn' : 'ok',
|
||||
'Large homepage images',
|
||||
count($heavy) . ' over 500KB',
|
||||
$heavy ? implode(', ', $heavy) : ''
|
||||
);
|
||||
}
|
||||
|
||||
return $f;
|
||||
}
|
||||
|
||||
private function psi(string $url, string $strategy): ?array {
|
||||
$cache_key = 'wph_psi_' . md5($url . '|' . $strategy);
|
||||
$cached = get_transient($cache_key);
|
||||
if ($cached !== false) return $cached;
|
||||
$api = add_query_arg([
|
||||
'url' => $url,
|
||||
'strategy' => $strategy,
|
||||
'category' => 'performance',
|
||||
], 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed');
|
||||
$resp = wp_remote_get($api, ['timeout' => 30]);
|
||||
if (is_wp_error($resp) || wp_remote_retrieve_response_code($resp) !== 200) {
|
||||
set_transient($cache_key, null, HOUR_IN_SECONDS);
|
||||
return null;
|
||||
}
|
||||
$data = json_decode((string) wp_remote_retrieve_body($resp), true);
|
||||
if (!is_array($data) || empty($data['lighthouseResult'])) {
|
||||
set_transient($cache_key, null, HOUR_IN_SECONDS);
|
||||
return null;
|
||||
}
|
||||
$lr = $data['lighthouseResult'];
|
||||
$out = [
|
||||
'performance' => $lr['categories']['performance']['score'] ?? null,
|
||||
'lcp' => $lr['audits']['largest-contentful-paint']['displayValue'] ?? null,
|
||||
'cls' => $lr['audits']['cumulative-layout-shift']['displayValue'] ?? null,
|
||||
'tbt' => $lr['audits']['total-blocking-time']['displayValue'] ?? null,
|
||||
];
|
||||
set_transient($cache_key, $out, 12 * HOUR_IN_SECONDS);
|
||||
return $out;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user