Skip to main content

benecaster_before_email_send

Action Free Since v1.0.0

Fires before any Benecaster email is dispatched, giving access to the fully resolved message for logging or side effects. This hook is suitable for logging and auditing only — the email bodies are already resolved and changes inside this callback do not affect what is sent.

A type-specific variant is available — append the email type to the hook name (e.g. benecaster_before_email_send_welcome) to target a single email type; the $email_type parameter is omitted on the type-specific variant. Stable built-in type strings: welcome, token_reset, token_revoked, donation_thank_you, broadcast, analytics_digest_daily, analytics_digest_weekly, analytics_digest_monthly, episode_notification.

To prevent an email from being dispatched, use the benecaster_email_should_send filter. To modify subject or body content, use the corresponding email body filters.

Parameters

Name Type Default Description
$email_type string Email type string (e.g. 'welcome', 'token_reset', 'broadcast')
$recipient string Recipient email address
$subject string Resolved subject line
$body_html string Resolved HTML body
$body_text string Resolved plain text body
$headers array Headers array passed to wp_mail()
$user_id int|null WordPress user ID, or null for admin-only emails
$show_id int|null Show ID, or null if not show-specific

Examples

Log all outbound emails

add_action( 'benecaster_before_email_send', function(
    string $email_type,
    string $recipient,
    string $subject,
    string $body_html,
    string $body_text,
    array  $headers,
    ?int   $user_id,
    ?int   $show_id
): void {
    error_log( sprintf(
        '[Benecaster Email] type=%s recipient=%s subject="%s"',
        $email_type, $recipient, $subject
    ) );
}, 10, 8 );

Type-specific variant for welcome emails

add_action( 'benecaster_before_email_send_welcome', function(
    string $recipient,
    string $subject,
    string $body_html,
    string $body_text,
    array  $headers,
    ?int   $user_id,
    ?int   $show_id
): void {
    // $email_type is omitted — it is encoded in the hook name
    error_log( '[Benecaster] Welcome email sending to: ' . $recipient );
}, 10, 7 );

Notes

All Benecaster emails send as multipart (HTML + plain text). Both bodies are passed to this hook for logging, but they are already resolved — changes to them here have no effect on the sent message. Do not use this hook to prevent or modify sends; use benecaster_email_should_send (filter) or the email body filters instead.