Skip to content

Core Lifecycle

mab056 edited this page Feb 15, 2026 · 3 revisions

Core Lifecycle

Activation

src/Core/Activator.php (activate()):

  • sets option ops_health_activated_at (first activation only)
  • sets option ops_health_version
  • registers custom cron interval every_15_minutes
  • schedules hook using constant Scheduler::HOOK_NAME (ops_health_run_checks) if not already scheduled
  • interval taken from constant Scheduler::INTERVAL (every_15_minutes)

Runtime Init

src/Core/Plugin.php (init()):

  • registers admin menu
  • registers dashboard widget
  • registers HealthScreen styles enqueue
  • registers scheduler hooks

Scheduler Runtime

src/Services/Scheduler.php:

  • cron hook: ops_health_run_checks (constant HOOK_NAME)
  • interval: every_15_minutes (constant INTERVAL)
  • throttled self-healing via transient ops_health_cron_check (1h)
  • run_checks():
    • reads previous results (if AlertManager is present)
    • executes run_all()
    • passes (current, previous) to AlertManager
    • protects cron with catch (\Throwable)

Deactivation

src/Core/Activator.php (deactivate()):

  • removes cron hook ops_health_run_checks
  • preserves plugin data

Uninstall

Uninstaller Class

src/Core/Uninstaller.php

The uninstall() method detects the installation type and dispatches:

uninstall()
├── is_multisite() → uninstall_network()
│   └── for each blog: switch_to_blog() → uninstall_single() → restore_current_blog()
└── else → uninstall_single()

uninstall_network() uses get_sites( [ 'fields' => 'ids' ] ) to get all blog IDs in the network, then iterates with switch_to_blog()/restore_current_blog() executing uninstall_single() for each blog.

Cleanup performed by uninstall_single():

  • plugin options (ops_health_activated_at, ops_health_version, ops_health_latest_results, ops_health_alert_settings, ops_health_alert_log)
  • cron hook (ops_health_run_checks) via wp_clear_scheduled_hook()
  • fixed transients (ops_health_cron_check, ops_health_admin_notice, ops_health_alert_notice)
  • dynamic cooldown transients via $wpdb query (LIKE _transient_ops_health_alert_cooldown_%)

uninstall.php Wrapper

uninstall.php has three branches:

  1. Autoloader available: loads Uninstaller and delegates (handles multisite internally)
  2. Multisite fallback (elseif is_multisite()): inline blog iteration with $ops_health_ prefixed variables
  3. Single-site fallback (else): direct inline cleanup

The WP_UNINSTALL_PLUGIN guard ensures the file is only executed during WordPress uninstallation.

For more details on multisite support, see Multisite Support.

Clone this wiki locally