benecaster_render_email_preview()
benecaster_render_email_preview( string $type, array $context = [], ?int $show_id = null ): array
Renders an email the way it would be sent, without sending, queueing or logging it: what a Preview button shows.
It runs the same merge-tag, subject and body filters as a real send, so a design stored by an email editor, a theme override and every add-on filter apply just as they would. It uses the subject and template the type registered (default_subject and default_template_path in benecaster_managed_email_types).
The data is simulated. Any tag the type can carry that $context and the show leave empty is filled with its sample from benecaster_get_email_merge_tag_catalog(). Real values, such as the show’s title, are never replaced.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
type |
string |
— | Yes | A registered email type slug. |
context |
array |
[] |
No | Tag values to use instead of the samples, keyed by tag name. |
show_id |
int|null |
null |
No | The show whose branding and show details to use, or null for an email with no show. |
Return Value
Type:
array
subject, html and text, as the email would be sent. html is empty when the type has no template and nothing supplies a body. All three are empty if the email could not be rendered.
Example
$preview = benecaster_render_email_preview( 'welcome', [], $show_id );
printf( '<h3>%s</h3>', esc_html( $preview['subject'] ) );
printf(
'<iframe sandbox srcdoc="%s" style="width:100%%;height:600px"></iframe>',
esc_attr( $preview['html'] )
);
Notes
Not for building mail to send yourself. Sending the result yourself skips the opt-out check, the email log and the List-Unsubscribe headers. Send through benecaster_send_email(), or offer a test with benecaster_send_test_email().
There is no capability check.
Need this built rather than just documented? See our services →