Auto-populate custom fields from imported RSS data
When the Migration Wizard or Feed Sync imports episodes, benecaster_feed_sync_import_data lets you reshape the raw RSS item data before it’s written, and benecaster_episode_imported fires after each episode is saved. Use this pair to map custom RSS namespace elements to Benecaster custom fields automatically during the import pass.
Code
<?php
add_action(
'benecaster_episode_imported',
function ( int $episode_id, int $show_id, array $source_item ): void {
// $source_item['raw_xml'] holds the untouched <item> as a SimpleXMLElement.
$item = $source_item['raw_xml'] ?? null;
if ( ! $item instanceof SimpleXMLElement ) {
return;
}
$ns = $item->getNamespaces( true );
if ( ! isset( $ns['mystudio'] ) ) {
return;
}
$mystudio = $item->children( $ns['mystudio'] );
$sponsor = trim( (string) ( $mystudio->sponsor ?? '' ) );
if ( '' !== $sponsor ) {
benecaster_update_field( 'sponsor', $sponsor, $episode_id );
}
},
10,
3
);