Read or save an episode’s Subscriber notification, and run code when it is saved
The Workbench’s Subscriber notification tile (id subscriber-notification, Publish, priority 30, before Episode status; off by default).
With the Email Editor on for the episode’s show, the tile reads the Email Editor’s per-episode choice (see Read what the podcaster chose for an episode’s notification) and never writes it. The choice is made only in the episode editor’s Ready to Publish? dialog, so before publish the tile reads Chosen when the episode is published, with Open in episode editor. Once the episode is published the tile is Done, with Using the notification template, Composed for this episode or No notification (nothing kept reads as the template). The tile cannot compose an email.
Without the Email Editor, or with it off for the show, the tile is a Subscribers notified box and notes.
- Reading:
GET …/workbench(see Read the Podcast Workflow Workbench over REST) carriesworkflow.subscriber_notification:{ email_editor, choice, choice_label, notified, notes, editor_url }.choiceis'',template,customornone, and stays''until the episode is published with the Email Editor on. - Saving (the box and notes, used while the Email Editor is off):
PUT /benecaster-podcast-workflow/v1/shows/{show_id}/episodes/{episode_id}/subscriber-notificationwith{ notified: bool, notes: string }, both every time. Notes are plain text, 10,000 characters at most (400 benecaster_podcast_workflow_guest_notes_too_long; the code is shared with the other tiles), a missing or mistyped field is400 benecaster_podcast_workflow_invalid_field, and the Workbench’s per-show checks apply. It answers the refreshed canvas and writes no episode note. - The tile’s state: with the Email Editor on, Not started before publish and Done once published, whatever was chosen. With it off, Done once the box is ticked, In progress once notes are saved, else Not started.
- The tile is declared with no
add_on, so it is asked for its state while the Email Editor is off. - benecaster_podcast_workflow_before_save_subscriber_notification and benecaster_podcast_workflow_after_save_subscriber_notification are actions,
( int $episode_id, bool $notified, string $notes, int $show_id ), around every save, with the notes as stored.
Code
<?php
// Post to the team chat when someone marks an episode's listeners as told.
add_action( 'benecaster_podcast_workflow_after_save_subscriber_notification', function ( int $episode_id, bool $notified, string $notes, int $show_id ): void {
if ( $notified ) {
my_plugin_post_to_chat( sprintf( 'Listeners told about %s', get_the_title( $episode_id ) ) );
}
}, 10, 4 );
Hooks Used
Need this built rather than just documented? See our services →