Skip to main content

benecaster_before_broadcast_send

Action Free

Fires once per broadcast sent with benecaster_send_broadcast(), after the broadcast is recorded and its recipients are known, and before any of them is sent to. It fires in the request that sent the broadcast.

Broadcasts go out in the background: benecaster_send_broadcast() returns as soon as this action has run, and WP-Cron then hands the recipients to the email queue in batches of 100. So when this fires, nobody has been queued yet, and nobody has been when the call returns either.

$user_ids is everyone the chosen audiences reached, each once, in ascending order. It is the list the batches work through: someone who joins a tier afterwards is not added. Each recipient’s opt-out is still checked when their batch runs, so some of them may not be mailed. A broadcast refused at the start (not a show, no audience, an empty subject or body) fires nothing.

Parameters

Name Type Default Description
$broadcast_id int — The broadcast's id, as listed by `GET /benecaster/v1/broadcasts`
$show_id int — ID of the show the broadcast is from
$audiences string[] — The audience slugs the broadcast was sent to, each once (`paying`, `followers`, `all`, `tier:SLUG`, or an add-on's own)
$user_ids int[] — The recipients' WordPress user IDs, each once, in ascending order

Examples

Record how many listeners a broadcast is going to

add_action( 'benecaster_before_broadcast_send', function (
    int   $broadcast_id,
    int   $show_id,
    array $audiences,
    array $user_ids
): void {
    update_option( 'my_addon_broadcast_reach_' . $broadcast_id, count( $user_ids ), false );
}, 10, 4 );

Notes

Every recipient is sent through Benecaster's normal email path, so the per-email filters and benecaster_after_email_send still run for each one, with the type broadcast, as their batch is worked. To act once the whole broadcast has been handed over, use benecaster_after_broadcast_send.

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