Carry per-reference tracking to the new show when an episode moves
A plugin that keeps a row per reference library item, such as a tracked redirect or a link-health record, loses track of a moved episode’s references: the episode now cites the new show’s items. benecaster_episode_references_moved passes a map of which item each one became. Copy, never move: the old item still serves the old show’s other episodes.
Two old items can map to one new item. Check before you insert, as below, or a unique key will refuse the second copy.
Code
<?php
add_action( 'benecaster_episode_references_moved', function ( int $episode_id, int $from_show_id, int $to_show_id, array $map ): void {
foreach ( $map as $old_item_id => $new_item_id ) {
$row = my_tracking_row( $from_show_id, (int) $old_item_id );
if ( null === $row || null !== my_tracking_row( $to_show_id, (int) $new_item_id ) ) {
continue; // Nothing tracked, or the destination item is already tracked (two items may share a value).
}
my_create_tracking_row( $to_show_id, (int) $new_item_id, $row );
}
}, 10, 4 );
Hooks Used
Need this built rather than just documented? See our services →