Skip to main content

benecaster_feed_sync_import_data

Filter Free

Filters the data array built from an RSS item before a draft episode is created during feed sync. Reshapes only the keys it documents — title, content, description_rss, post_date, audio_url, file_size, mime_type, duration, episode_number, season_number, episode_type, explicit, author, episode_artwork, source_guid, source_link — a key you invent is ignored. Use to transform or augment imported data — for example, to parse a custom RSS namespace and map it to a Benecaster custom field.

Parse custom RSS namespace and map to Benecaster custom field

Free Intermediate

benecaster_feed_sync_import_data fires during core Feed Sync, before the draft is created. It reshapes only the keys it documentstitle, content, description_rss, post_date, audio_url, file_size, mime_type, duration, episode_number, season_number, episode_type, explicit, author, episode_artwork, source_guid, source_link. A key you invent is ignored — custom_fields is not one of them, and Feed Sync never reads it. Use this filter to feed a documented field from a custom namespace your old host wrote: here, the host’s canonical episode page overrides the <link> captured as _benecaster_source_link.

To store a value that has no documented key, let the draft be created and write it into a Benecaster custom field with benecaster_update_field() on benecaster_episode_imported instead — see auto-populate-custom-fields-from-rss-import. That hook also covers the setup wizard’s one-time import, which runs no filters at all.

<?php
add_filter(
    'benecaster_feed_sync_import_data',
    function ( array $episode_data, SimpleXMLElement $rss_item, int $show_id ): array {
        $ns = $rss_item->getNamespaces( true );

        if ( ! isset( $ns['myshow'] ) ) {
            return $episode_data;
        }

        $myshow    = $rss_item->children( $ns['myshow'] );
        $canonical = trim( (string) ( $myshow->canonical_url ?? '' ) );

        if ( '' !== $canonical ) {
            // Revalidated after this filter; a non-http value stores no link.
            $episode_data['source_link'] = $canonical;
        }

        return $episode_data;
    },
    10,
    3
);

View on GitHub →

Parameters

Name Type Default Description
$data array Episode data array built from the RSS item
$rss_item SimpleXMLElement The RSS item being imported
$show_id int ID of the show

Returns: array

Example

add_filter( 'benecaster_feed_sync_import_data', function( $data, $rss_item, $show_id ) {
    // Pull a custom <myshow:sponsor> RSS element and map it to a Benecaster custom field.
    $ns      = $rss_item->children( 'https://myshow.example.com/rss/1.0' );
    $sponsor = isset( $ns->sponsor ) ? (string) $ns->sponsor : '';
    if ( $sponsor ) {
        $data['meta']['_episode_sponsor'] = sanitize_text_field( $sponsor );
    }
    return $data;
}, 10, 3 );

Notes

source_link (added feature/import-source-link, 2026-09-15; additive — existing callbacks are unaffected) is the item's <link>, the episode's page on the old host, already validated by EpisodeMeta::sanitize_source_link() (http/https with a host, at most 2048 characters); '' when the item has none or it's unusable. It becomes the _benecaster_source_link post meta. Your value is validated again after the filter: set it to another URL to replace it, or unset it or set it to '' to store no link. A non-http value is dropped, not stored.

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