Skip to main content

Audit who acknowledged an admin notice

Free Beginner

Record which admin dismissed a notice and when, for an audit trail or an ops channel. benecaster_notice_dismissed fires once per real dismissal — never for a repeat, a missing notice, or a notice the system cleared itself — so every call is a person acknowledging something. Match on the notice-ID prefix you care about; notice IDs are namespaced by the code that published them.

Code

<?php
add_action( 'benecaster_notice_dismissed', function ( string $notice_id ): void {
    // Only security alerts, e.g. the invalid-token spike alert.
    if ( ! str_starts_with( $notice_id, 'benecaster_invalid_token_alert_' ) ) {
        return;
    }

    $user = wp_get_current_user();
    my_ops_alert( sprintf(
        '%s acknowledged security alert %s at %s',
        $user->exists() ? $user->user_login : 'unknown user',
        $notice_id,
        wp_date( 'Y-m-d H:i T' ) // Site time, from a real UTC timestamp.
    ) );
} );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →