Files
wp-healthcheck/includes/class-wph-steps.php
Steve Hanlon 8de7cad0de Phase 1 MVP: drop-in step registry + session + Markdown report
Plugin skeleton, drop-in step registry, option-backed session, single-page
checklist UI, downloadable Markdown report. Steps live as one file each
under includes/steps/ — adding/removing one is a single file change.
Step IDs are stable strings so renaming files preserves session data.

Architecture (hc-5ix.3): WPH_Steps singleton globs includes/steps/*.php,
natsort-orders by filename, requires each file (which returns a WPH_Step
instance), then applies a 'wph_steps' filter so installs can drop steps.

Session (hc-5ix.4): option-backed (per decision — plugin is installed
per-engagement, so DB-resident history would be lost on uninstall).
Single in-progress session per site; finished sessions render a report
that the user downloads/copies.

Recovery bootstrap (hc-5ix.1): detects whether wp-site-recovery is
installed + active, surfaces state on the start panel and in every
active session. Manual install for now; private update channel deferred
to hc-5ix.27.

Smoke-tested on testsite: registry discovery (13 steps in correct order),
start → update_step → progress count → finish → 8KB Markdown report →
discard cycle.
2026-06-11 15:49:29 +01:00

56 lines
1.6 KiB
PHP

<?php
if (!defined('ABSPATH')) exit;
/**
* Step registry. Singleton.
*
* discover() globs a directory for *.php files in sort order and requires each.
* Each file MUST return a WPH_Step instance. The numeric filename prefix
* (00, 10, 20...) controls the visual order.
*
* After discovery, the 'wph_steps' filter lets installation-specific code
* remove/replace steps (return the array keyed by step id).
*/
final class WPH_Steps {
private static ?WPH_Steps $instance = null;
/** @var array<string,WPH_Step> */
private array $steps = [];
private bool $discovered = false;
public static function instance(): WPH_Steps {
return self::$instance ??= new self();
}
public function discover(string $dir): void {
if ($this->discovered) return;
$files = glob(rtrim($dir, '/') . '/*.php') ?: [];
// Natural sort so 100-* comes after 20-* (not after 10-*).
natsort($files);
$files = array_values($files);
foreach ($files as $file) {
$obj = require $file;
if ($obj instanceof WPH_Step) {
$this->steps[$obj->id()] = $obj;
}
}
/**
* Filter the loaded steps. Return an array keyed by step id.
* To drop a step on a particular install: unset($steps['backup']).
*/
$this->steps = apply_filters('wph_steps', $this->steps);
$this->discovered = true;
}
/** @return array<string,WPH_Step> */
public function all(): array {
return $this->steps;
}
public function get(string $id): ?WPH_Step {
return $this->steps[$id] ?? null;
}
}