Skip to main content

Read or change a show’s preset task list, and run code when a show saves it

Premium Intermediate Podcast Workflow

A show’s Workflow settings tab → Preset tasks holds the tasks every new episode’s production plan starts from (see Read or change an episode’s production plan, change how a new plan starts, and run code when a plan is finalised).

A task is { id, name, offset_days, duration_days }:

  • offset_days is its due date in whole days from the episode’s publish date: negative before, 0 on publish day, positive after, from −365 to 365.
  • duration_days is how long it runs, ending on that due date (1 to 365), so a 7-day task due at −28 starts at −34.
  • id is stable across saves. The default list’s ids start default-; a new task gets task- and 12 hex digits.

The list is stored whole in the show’s post meta _benecaster_workflow_task_list (a JSON list). With no saved list the show uses the default list of fifteen tasks, translated when it is read; a saved [] is an empty list.

  • GET /benecaster-podcast-workflow/v1/shows/{show_id}/task-list answers { tasks, customised, defaults }: the show’s list (the default list until it saves one), whether it has saved one, and the default list.
  • PUT …/task-list sends { tasks: [ { id?, name, offset_days, duration_days } ] }, the whole list in order, at most 100 tasks. A missing, invalid or repeated id is replaced with a new one. Anything else invalid is 400 benecaster_podcast_workflow_invalid_task_list with data.index, the row at fault, and nothing is saved. It answers as GET does.
  • Both routes need benecaster_rest_permission_admin, then refuse with 404 benecaster_podcast_workflow_show_not_found or 403 benecaster_podcast_workflow_off_for_show.
  • benecaster_podcast_workflow_before_save_preset_tasks and benecaster_podcast_workflow_after_save_preset_tasks are actions, ( int $show_id, array $tasks ), around the save, $tasks being the list as stored.

Code

<?php
add_action( 'benecaster_podcast_workflow_after_save_preset_tasks', function ( int $show_id, array $tasks ): void {
    $longest = max( array_column( $tasks, 'duration_days' ) ?: [ 0 ] );
    update_post_meta( $show_id, '_my_plugin_longest_task', $longest );
}, 10, 2 );

View on GitHub →

Hooks Used

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