Skip to main content

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.

Code

<?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 →

Hooks Used

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