benecaster_episode_imported
Fires after each draft episode is created from a hosting feed — by Feed Sync (Feed\FeedImporter) and by the one-time bulk import (Feed\FeedBulkImporter, the setup wizard’s Import Episodes step) alike, not only during a feed sync. The draft post and all mappable meta fields are already set. Use to auto-populate additional fields, trigger external actions, or modify the draft before the podcaster reviews it.
Clean up captured source links on import
Both core import paths — the setup wizard’s one-time import and Feed Sync — store each RSS <item><link> (the episode’s page on the old host) as _benecaster_source_link, validated by EpisodeMeta::sanitize_source_link() (http/https with a host, at most 2048 characters; anything else leaves the key unset). Many hosts append campaign parameters to that link. Because benecaster_episode_imported fires from both import paths after the meta is written, one callback cleans up both — the wizard import runs no filters at all, so there’s no earlier point to hook.
Nothing in core fetches that page: it’s stored for reference, and read back with EpisodeMeta::get_source_link(), as read-only source_link on GET /episodes/{id}, in the site data export, and through the core wp/v2 meta registration. To change the value before the draft exists — for Feed Sync only — set source_link on benecaster_feed_sync_import_data instead; it’s revalidated after your callback runs.
<?php
add_action(
'benecaster_episode_imported',
function ( int $episode_id, int $show_id, SimpleXMLElement $rss_item ): void {
$meta = new \Benecaster\Episode\EpisodeMeta( $episode_id );
$link = $meta->get_source_link();
if ( '' === $link ) {
return; // No usable <link> on the item.
}
$parts = wp_parse_url( $link );
parse_str( $parts['query'] ?? '', $query );
foreach ( [ 'utm_source', 'utm_medium', 'utm_campaign', 'ref' ] as $drop ) {
unset( $query[ $drop ] );
}
// set_source_link() revalidates and, on a bad value, removes the key
// rather than storing ''.
$meta->set_source_link(
$parts['scheme'] . '://' . $parts['host'] . ( $parts['path'] ?? '' )
. ( [] === $query ? '' : '?' . http_build_query( $query ) )
);
},
10,
3
);
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$episode_id |
int |
— | ID of the created draft episode post |
$show_id |
int |
— | ID of the parent show |
$rss_item |
SimpleXMLElement |
— | The raw RSS item that was imported |
Need this built rather than just documented? See our services →