Skip to main content

benecaster_sponsor_manager_get_sponsor_episodes()

Episode Premium sponsor-manager
benecaster_sponsor_manager_get_sponsor_episodes( int $sponsor_id ): array

The episodes a sponsor is on, for an add-on that reports on a sponsor’s reach, such as Analytics Dashboard’s Sponsors panel. A sponsor is one record for the whole site, so its episodes may come from several shows. 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
sponsor_id int — Yes A benecaster_sponsor post id.

Return Value

Type: array

The sponsor's episodes, newest first by the episode's date, each [ 'episode_id' => int, 'show_id' => int, 'status' => string, 'positions' => string[], 'campaign' => array|null ]. status is the episode's post_status (any but trash, auto-draft and revision); keep status === 'publish' for published episodes only. campaign is shaped as in benecaster_sponsor_manager_get_episode_sponsors(). Only episodes of shows the sponsor has a campaign on and where Sponsor Manager is on. [] for an id that is not a sponsor, or a sponsor on no such episode.

Example

$episodes = function_exists( 'benecaster_sponsor_manager_get_sponsor_episodes' )
    ? benecaster_sponsor_manager_get_sponsor_episodes( $sponsor_id )
    : [];

foreach ( $episodes as $row ) {
    if ( 'publish' === $row['status'] && benecaster_user_can_access_episode( $row['episode_id'], get_current_user_id() ) ) {
        echo esc_html( get_the_title( $row['episode_id'] ) );
    }
}

Hooks Fired

Notes

Ids only; no access is decided. Before you show an episode to a visitor, ask benecaster_user_can_access_episode() ( $episode_id, $user_id ).

Never a contact or a rate. Of a campaign, only its id, name and dates are returned.

It is loaded on every request while Sponsor Manager is active, whether or not it is on for any show, and leaves out episodes of shows where it is off. 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.

To refresh a cache when a sponsor's episodes change, hook benecaster_sponsor_manager_after_save_episode_sponsors.

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