*/ 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 */ public function all(): array { return $this->steps; } public function get(string $id): ?WPH_Step { return $this->steps[$id] ?? null; } }