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:
2026-06-11 16:13:15 +01:00
parent 0d51fc3b59
commit cf3007ec37
10 changed files with 706 additions and 20 deletions

View File

@@ -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;
}
};

View File

@@ -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;
}
};

View File

@@ -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;
}
};

View File

@@ -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;
}
};

View File

@@ -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;
}
};

View File

@@ -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;
}
};