Act on the episodes a podcaster ticks — and badge each row with your status
Your add-on processes episodes — transcribes them, pushes them somewhere, re-checks their audio. Let the podcaster tick rows on Benecaster → Episodes and choose your action, and show where each episode stands. window.BenecasterExtensions.registerEpisodeBulkAction() adds the action; the BenecasterEpisodeListRow slot draws a badge on each row; and window.BenecasterExtensions.addonIsActive() keeps the badge to shows where your add-on is on.
The action posts to your add-on’s own route. Check the capability and that your add-on is on for that show there:
// The route the action posts to. Check the capability AND that your add-on is on for that show.
register_rest_route( 'my-addon/v1', '/process', [
'methods' => 'POST',
'permission_callback' => fn () => current_user_can( 'manage_options' ),
'callback' => function ( WP_REST_Request $request ) {
$show_id = (int) $request['show_id'];
if ( ! benecaster_addon_is_active( 'my-addon', $show_id ) ) {
return new WP_Error( 'not_active', __( 'My Add-on is not switched on for this show.', 'my-addon' ), [ 'status' => 403 ] );
}
$ids = array_map( 'absint', (array) $request['episode_ids'] );
foreach ( $ids as $id ) {
as_enqueue_async_action( 'my_addon_process_episode', [ $id ] ); // never do slow work in the request
}
/* translators: %d: number of episodes */
return [ 'message' => sprintf( _n( '%d episode queued.', '%d episodes queued.', count( $ids ), 'my-addon' ), count( $ids ) ) ];
},
] );
Code
wp.domReady( () => {
const { registerEpisodeBulkAction, registerFill, addonIsActive, React } = window.BenecasterExtensions;
registerEpisodeBulkAction( {
id: 'my-addon-process',
label: wp.i18n.__( 'Process selected', 'my-addon' ),
addon: 'my-addon', // offered only where it is licensed and switched on
route: 'my-addon/v1/process', // Benecaster POSTs { episode_ids, show_id } with the nonce
} );
registerFill( 'BenecasterEpisodeListRow', ( { episodeId, showId } ) => {
if ( ! addonIsActive( 'my-addon', showId ) ) return null; // Benecaster cannot gate a fill for you
const status = window.myAddonStatuses?.[ episodeId ]; // fetched once for the page, not per row
return status ? React.createElement( 'span', { className: 'my-addon-badge' }, status ) : null;
} );
} );
Need this built rather than just documented? See our services →