Files
wp-healthcheck/includes/class-att-hc-steps.php
Steve Hanlon 6dd050ea1d Rename to ATT Site Healthcheck (private prefix)
Wholesale rename to avoid clashes with generic 'site healthcheck'
plugin names on a target site:

  - Plugin Name:        'Site Healthcheck' → 'ATT Site Healthcheck'
  - Main file:          site-healthcheck.php → att-site-healthcheck.php
  - Plugin folder:      site-healthcheck → att-site-healthcheck
  - Admin menu slug:    site-healthcheck → att-site-healthcheck
  - Settings slug:      site-healthcheck-settings → att-site-healthcheck-settings
  - PHP class prefix:   WPH_ → ATT_HC_
  - Function prefix:    wph_ → att_hc_
  - Option / transient: wph_* → att_hc_*
  - Action/filter:      wph_* → att_hc_*
  - CSS class prefix:   wph- → att-hc-
  - Constants:          WPH_GITEA_* → ATT_HC_GITEA_*
  - Class file names:   class-wph-*.php → class-att-hc-*.php
  - Dev folder:         ~/dev/wp-healthcheck → ~/dev/att-site-healthcheck

Existing in-progress sessions on installs that had the old wph_session
option will not migrate — they were intended for dev use only and the
user has confirmed this is OK for the rename window.

Smoke-tested on testsite: classes load, 14 steps discovered, save/load
round-trip works, admin page renders with new att-hc- CSS classes.

Recovery plugin detection unchanged — that lives in wp-site-recovery
and continues to be detected by Name + Author header.
2026-06-12 11:11:42 +01:00

56 lines
1.7 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 ATT_HC_Step instance. The numeric filename prefix
* (00, 10, 20...) controls the visual order.
*
* After discovery, the 'att_hc_steps' filter lets installation-specific code
* remove/replace steps (return the array keyed by step id).
*/
final class ATT_HC_Steps {
private static ?ATT_HC_Steps $instance = null;
/** @var array<string,ATT_HC_Step> */
private array $steps = [];
private bool $discovered = false;
public static function instance(): ATT_HC_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 ATT_HC_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('att_hc_steps', $this->steps);
$this->discovered = true;
}
/** @return array<string,ATT_HC_Step> */
public function all(): array {
return $this->steps;
}
public function get(string $id): ?ATT_HC_Step {
return $this->steps[$id] ?? null;
}
}