Skip to main content

Run a health check on the daily license cron in addition to the once-per-admin-session sweep

Free Intermediate Since v1.0.0

Attach a health check to benecaster_license_cron_complete so the notice shows up even if no admin ever opens wp-admin between firings. Use NoticeManager::run_health_check( $check ) rather than $check->evaluate() directly — it wraps the call in the same exception-swallowing contract as the admin-session sweep. Skip add_health_check() registration and only attach to benecaster_license_cron_complete if your check is too expensive to run on every admin session (e.g. it makes a slow outbound HTTP request).

Code

<?php
add_action( 'benecaster_boot', function ( \Benecaster\Container $container ): void {
    $notices = $container->make( NoticeManager::class );
    $check   = new StripeWebhookHealthCheck( $notices );

    // Admin-pageload sweep (transient-gated, once per session).
    $notices->add_health_check( $check );

    // Daily cron sweep — also runs the check on a fixed cadence so the
    // notice shows up even if no admin ever opens wp-admin between firings.
    add_action(
        'benecaster_license_cron_complete',
        function () use ( $notices, $check ): void {
            $notices->run_health_check( $check );
        }
    );
} );

View on GitHub →

Hooks Used