Skip to main content

benecaster_feed_request_dispatched

Action Free Since v1.0.0

Fires from FeedController::dispatch() after every feed-URL dispatch decision, for all four possible token states: valid, over_limit, revoked, and not_found. The payload is a single associative array describing the request context.

Consumed internally by FeedRequestLogger (which writes the row to benecaster_feed_request_log subject to the log-enabled and log-level options), but designed as a public extension surface. Add-ons and site code can hook here for realtime feed-request notifications — for example, a Slack ping when a cancelled subscriber’s app is still polling, or an alerting layer on top of the built-in log.

token_id and token_prefix are null when token_status is not_found (no matching token row). Geo fields (country_code, region_code) are null when the site has no GeoIP database configured or the lookup returns no result.

Parameters

Name Type Default Description
$context array Request context array. Keys: `show_id` (int), `token_id` (?int — null on not_found), `token_prefix` (?string — first 8 chars of the plaintext token, null on not_found), `token_status` (string: 'valid' | 'over_limit' | 'revoked' | 'not_found'), `ip_hash` (string — SHA-256 hash of the requester's IP using benecaster_ip_hash_salt), `user_agent` (string), `country_code` (?string — ISO 3166-1 alpha-2, null when GeoIP unavailable), `region_code` (?string — ISO 3166-2 region, null when GeoIP unavailable)

Examples

Slack alert when a cancelled subscriber's app is still polling

add_action( 'benecaster_feed_request_dispatched', function ( array $ctx ): void {
    if ( $ctx['token_status'] !== 'revoked' ) {
        return;
    }
    wp_remote_post( MY_SLACK_WEBHOOK_URL, [
        'body' => wp_json_encode( [
            'text' => sprintf(
                'Revoked token poll detected — show %d, prefix %s, country %s',
                $ctx['show_id'],
                $ctx['token_prefix'] ?? 'n/a',
                $ctx['country_code'] ?? 'unknown'
            ),
        ] ),
    ] );
} );

Notes

The built-in feed request log (benecaster_feed_request_log) already records the same data for all four token statuses. The primary value of hooking this action directly is building a rate-limiting or realtime-alerting layer on top of the log, not re-implementing the log itself. For custom rate limiting, compare the token_prefix or ip_hash field against your own counter store.