Files
wp-healthcheck/includes/recovery-bootstrap.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

93 lines
4.5 KiB
PHP

<?php
if (!defined('ABSPATH')) exit;
/**
* Step-0 bootstrap: ensure wp-site-recovery is installed + active before the
* stepper runs (bead hc-5ix.1, references decision hc-5ix.26).
*
* Detection is by plugin folder slug, not by main-file path, because the slug
* is stable across releases. If we ever publish a private update channel for
* the recovery plugin, this is also where we'd offer "fetch latest".
*/
final class ATT_HC_Recovery_Bootstrap {
/**
* Detect by plugin Name + Author rather than folder slug — the recovery
* plugin can be installed under any folder (site-recovery/, wp-site-recovery/,
* etc.) depending on how it was unpacked. Cache the result per request.
*/
private const NAME = 'Site Recovery';
private const AUTHOR = 'Steve Hanlon';
/** Return the plugin_basename (folder/file.php) if installed, or null. */
public static function plugin_file(): ?string {
static $cached;
if ($cached !== null) return $cached === '' ? null : $cached;
if (!function_exists('get_plugins')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
foreach (get_plugins() as $file => $meta) {
if (($meta['Name'] ?? '') === self::NAME && strpos((string) ($meta['Author'] ?? ''), self::AUTHOR) !== false) {
return $cached = $file;
}
}
$cached = '';
return null;
}
public static function is_installed(): bool {
return self::plugin_file() !== null;
}
public static function is_active(): bool {
$file = self::plugin_file();
if (!$file) return false;
if (!function_exists('is_plugin_active')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return is_plugin_active($file);
}
public static function recovery_admin_url(): string {
return admin_url('tools.php?page=site-recovery');
}
/**
* Render a status panel that the admin page calls from the "Before you start"
* section. Shows install state, links to recovery settings when active, and
* offers a one-click install from gitea when missing+configured.
*/
public static function render_status(): void {
$installed = self::is_installed();
$active = $installed && self::is_active();
$file = self::plugin_file();
$configured = ATT_HC_Recovery_Installer::is_configured();
?>
<div class="att-hc-bootstrap-panel">
<h3>Recovery plugin status</h3>
<?php if ($active): ?>
<p class="att-hc-ok">✓ <strong>Site Recovery</strong> is installed and active <code><?php echo esc_html((string) $file); ?></code>.
<a href="<?php echo esc_url(self::recovery_admin_url()); ?>">Open recovery settings</a> to copy the URL + password into the client record.</p>
<?php elseif ($installed): ?>
<p class="att-hc-warn">⚠ <strong>Site Recovery</strong> is installed but inactive <code><?php echo esc_html((string) $file); ?></code>. <a href="<?php echo esc_url(admin_url('plugins.php')); ?>">Activate it</a> before starting work.</p>
<?php else: ?>
<p class="att-hc-bad">✗ <strong>Site Recovery</strong> is not installed. Install it before starting the healthcheck — it's the safety net while we work on the site.</p>
<?php if ($configured): ?>
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" style="display:inline" onsubmit="return confirm('Download and install Site Recovery from gitea?');">
<?php wp_nonce_field('att_hc_recovery_install'); ?>
<input type="hidden" name="action" value="att_hc_recovery_install">
<button class="button button-primary">Install from gitea (latest)</button>
</form>
<a href="<?php echo esc_url(admin_url('tools.php?page=att-site-healthcheck-settings')); ?>" class="button">Configure source</a>
<?php else: ?>
<p>
<a href="<?php echo esc_url(admin_url('tools.php?page=att-site-healthcheck-settings')); ?>" class="button button-primary">Configure gitea source</a>
<em>— or install manually via Plugins → Add New → Upload Plugin.</em>
</p>
<?php endif; ?>
<?php endif; ?>
</div>
<?php
}
}