HealthCheck
\Benecaster\Notices\HealthChecks\HealthCheck
The contract for a health check: a small object that inspects one condition and keeps one admin notice in step with it. The NoticeManager calls evaluate() and does nothing else with the object, so a check owns both halves of its job. It publishes its notice when it finds the problem and deletes that notice when the problem is gone, and neither path may assume the other ran before.
This is the one extension point in the notices area. An add-on can implement the interface and register the check from a benecaster_boot callback with NoticeManager::add_health_check(), using the manager from the service container. By then the plugin has registered its own checks, and the manager has not yet run any of them. Registered checks run inside NoticeManager::generate_health_notices(), which fires on admin_init and is gated by a one-hour transient, so a check runs at most once an hour and only when an admin page loads. There is no filter for registering checks; add_health_check() is the only route.
A check that must not wait for an admin page load can also be run on the daily license cron, the way the plugin runs its feed, license-server and donation-decline checks. Hook benecaster_license_cron_complete and pass the check to NoticeManager::run_health_check().
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
evaluate(): void |
Public | — | Runs the check. When the condition is present, call NoticeManager::publish() with a stable notice_id, which creates the notice or refreshes it. When the condition is absent, call NoticeManager::delete() with the same ID. Both paths must be safe to repeat, because the sweep and the cron can each run the check. Returns nothing. An exception thrown here is caught by NoticeManager::run_health_check(), so a failing check can't break the other checks or the admin page. The failure is written to the Debug Log at error level, naming the check class, the exception, the message, the file and the line, and then benecaster_health_check_failed fires. |
Notes
The Debug Log reaches the site owner and support, not the add-on that registered the check. To hear about your own check's failures, listen on benecaster_health_check_failed and match your class with instanceof. A check that throws may have missed raising its notice or left a stale one up, so catch errors inside evaluate() if you need to decide which. The hourly gate is shared by all checks: the transient is set before the first check runs, so a check added after the sweep has run waits for the next window.