Skip to main content

benecaster_sponsor_manager_get_episode_sponsors()

Episode Premium sponsor-manager
benecaster_sponsor_manager_get_episode_sponsors( int $episode_id ): array

An episode’s sponsors and their ad positions, for an add-on that shows or reports on them, such as Podcast Workflow’s Sponsor confirmation tile or Analytics Dashboard’s Sponsors panel. It is the one supported way to read them: never read the assignments table. See Read an episode’s sponsors, or a sponsor’s episodes, from another add-on.

Parameters

Name Type Default Required Description
episode_id int — Yes A benecaster_episode post id.

Return Value

Type: array

The episode's sponsors in the episode's order, each [ 'sponsor_id' => int, 'company' => string, 'positions' => string[], 'archived' => bool, 'campaign' => array|null, 'confirmed' => bool ]. positions is one or more of pre_roll, mid_roll, post_roll, in that order. archived is true for a sponsor archived on the Sponsors screen after it was assigned (archiving keeps assignments). campaign is the campaign the assignment is tied to, [ 'id' => int, 'name' => string, 'start_date' => string, 'end_date' => string ] (dates YYYY-MM-DD or ''), or null for no campaign. confirmed is whether the sponsor's read on this episode has been confirmed; Sponsor Manager clears it when the sponsor's campaign or positions on the episode change. Only sponsors with a campaign on the episode's show are returned. [] for an id that is not an episode, an episode with no sponsors, or an episode on a show where Sponsor Manager is off.

Example

if ( function_exists( 'benecaster_sponsor_manager_get_episode_sponsors' ) ) {
    foreach ( benecaster_sponsor_manager_get_episode_sponsors( $episode_id ) as $sponsor ) {
        printf( '<li>%s (%s)</li>', esc_html( $sponsor['company'] ), esc_html( implode( ', ', $sponsor['positions'] ) ) );
    }
}

Hooks Fired

Notes

Never a contact or a rate. The company name is the only sponsor field returned, and of a campaign only its id, name and dates.

No access or status check on the episode. When you show sponsors to a visitor, decide first whether that visitor may see the episode.

Values are raw text, so escape them on output. It is loaded on every request while Sponsor Manager is active, whether or not it is on for any show, and answers for itself whether it is on for the episode's show. Guard calls with function_exists(), since Sponsor Manager may not be installed. Keys may be added in later versions; none will be removed or change meaning.

For the episodes a sponsor is on, use benecaster_sponsor_manager_get_sponsor_episodes(). To refresh a cache when an episode's sponsors change, hook benecaster_sponsor_manager_after_save_episode_sponsors.

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