Preview the Analytics Dashboard digest emails, or restyle them
The three digests are ordinary Benecaster email types, sent through benecaster_send_email() with show_id in the context, so every core email filter applies to them. They are registered 'unsubscribable' => false: core adds no broadcast unsubscribe footer or List-Unsubscribe header, and a subscriber-broadcast opt-out never stops them. Their own Unsubscribe link does. To see one as it would be sent today, with the show’s figures, sent to nobody:
- It is rendered by core’s
benecaster_render_email_preview(), so a theme override and an Email Editor design show as they would be sent.would_sendis false, withreasonemptyorthreshold, when today’s run would skip it; the pause, the day and the recipients are not considered. Same permission and403as the other Analytics Dashboard routes. - Restyle the body by copying the add-on’s
templates/emails/analytics-digest.phpto[theme]/benecaster/emails/analytics-digest.php. Its merge tags:digest_type,digest_title,digest_period(the UTC days, in words),digest_sections(JSON[ { id, title, lines } ], plain text: escape every line),digest_manage_url,digest_unsubscribe_url,digest_unsubscribe_label. Section ids:notable_callout,subscriber_snapshot,new_and_lost,episode_pulse,feed_engagement,cohort_highlight(monthly),benchmark_comparison. Keep both footer links: they are the only way out of this email. - Periods are the last complete UTC ones: daily = yesterday, weekly = the 7 days to yesterday, monthly = last calendar month. A digest with nothing to report is never sent.
- When: one single WP-Cron event,
benecaster_analytics_digest_check, set for the soonest show due and set again after each run, on every settings save and whenever it is missing. Each show gets at most one digest a site-local day, after its send time: monthly on its day, else weekly on its day, else daily. Don’t schedule it yourself; to run it now,wp cron event run benecaster_analytics_digest_check. digest_manage_urlholdsbenecaster_get_admin_url( '/analytics/settings', $show_id ), so Manage digest preferences → opens the email’s own show after log-in.- The unsubscribe link is
/?benecaster_analytics_digest={token}, signed with an HMAC of the site’sAUTHsalt and never expiring. Opening it only shows a confirm page; its button (aPOST) unsubscribes that person from that digest on that show. Never build one yourself: a changed token is refused.
Code
const url = window.benecasterAnalyticsDashboard.apiUrl + 'analytics/digest/preview';
const preview = await ( await fetch( url, {
method: 'POST',
headers: { 'X-WP-Nonce': window.benecasterAdmin.nonce, 'Content-Type': 'application/json' },
body: JSON.stringify( { show_id: 12, type: 'weekly' } ),
} ) ).json();
// { show_id, type, subject, html, text, would_send: true, reason: null }
Need this built rather than just documented? See our services →