Skip to main content

Add Feed Credits from Your Own Add-on

Premium Intermediate

Add read-only Podcasting 2.0 credits to an episode from your own add-on’s data, without writing to post meta. Benecaster calls benecaster_podcast2_episode_auto_feed_credits after loading meta-stored credits, merges the returned array into the feed render and the episode editor’s Feed Credits (as locked rows marked via {source}), and discards it: nothing is persisted. The example reads people from a custom post type of its own (my_addon_guest) linked through episode meta; swap in whatever your add-on stores.

Guest Manager already does this for its guests. On a site running Guest Manager, don’t add the same guests again from its data, or each one appears in the feed twice.

Every credit needs a role, a name and a source. One missing any of them is dropped from both the editor and the feed, so check the record you read from has a name before you add it.

Code

<?php
add_filter(
    'benecaster_podcast2_episode_auto_feed_credits',
    function ( array $credits, int $episode_id, int $show_id ): array {
        $guest_ids = (array) get_post_meta( $episode_id, '_my_addon_episode_guests', true );
        foreach ( $guest_ids as $guest_id ) {
            $post = get_post( (int) $guest_id );
            if ( ! $post || 'my_addon_guest' !== $post->post_type ) {
                continue;
            }
            $credits[] = [
                'role'       => 'guest',
                'name'       => $post->post_title,
                'url'        => (string) get_post_meta( $post->ID, 'website', true ),
                'image'      => (string) get_post_meta( $post->ID, 'photo_url', true ),
                'source'     => 'My Add-on',
                'source_url' => admin_url( 'post.php?post=' . $post->ID . '&action=edit' ),
            ];
        }
        return $credits;
    },
    10,
    3
);

View on GitHub →

Hooks Used

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