Skip to main content

Keep your plugin’s per-show episode data with an episode that moves show

Free Intermediate

A podcaster can move an episode to another show from the episode editor’s Show field, and Benecaster moves only what it owns. A plugin that stores rows keyed to an episode and its show (a sync record, a per-show redirect, a sponsorship slot) moves its own on benecaster_episode_move_after.

If your plugin sells access to an episode in a way Benecaster can’t see, refuse the move through benecaster_episode_move_blockers instead of letting a buyer lose it. The podcaster sees your label in the editor and can act on it.

Code

<?php
add_action( 'benecaster_episode_move_after', function ( int $episode_id, int $from_show_id, int $to_show_id ): void {
    global $wpdb;
    $wpdb->update(
        $wpdb->prefix . 'my_sponsor_slots',
        [ 'show_id' => $to_show_id ],
        [ 'episode_id' => $episode_id, 'show_id' => $from_show_id ],
        [ '%d' ],
        [ '%d', '%d' ]
    );
}, 10, 3 );

add_filter( 'benecaster_episode_move_blockers', function ( array $blockers, int $episode_id ): array {
    if ( my_store_sells_episode( $episode_id ) ) {
        $blockers[] = [
            'type'  => 'my_store_sale',
            'label' => __( 'This episode is for sale in My Store. Remove it from the sale first.', 'my-store' ),
        ];
    }
    return $blockers;
}, 10, 2 );

View on GitHub →

Hooks Used

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