Skip to main content

Stream every authenticated 302-proxy download event to an external webhook

Free Beginner Since v1.0.0

benecaster_download_logged fires from DownloadLog::record() immediately after a row lands in benecaster_download_log. Use it to fan the event out to a webhook receiver, Slack channel, or real-time pipeline without touching the proxy code path. Pair with benecaster_download_log_entry (see tag-download-log-rows-with-extra-data) to append custom columns before insertion.

Code

<?php
add_action(
    'benecaster_download_logged',
    function ( int $episode_id, int $user_id, array $log_entry ): void {
        wp_remote_post(
            'https://example.com/webhooks/benecaster-downloads',
            [
                'timeout'  => 5,
                'blocking' => false,
                'body'     => wp_json_encode( [
                    'episode_id'   => $episode_id,
                    'user_id'      => $user_id,
                    'tier_slug'    => $log_entry['tier_slug'] ?? null,
                    'requested_at' => gmdate( 'c' ),
                ] ),
            ]
        );
    },
    10,
    3
);

View on GitHub →

Hooks Used