Skip to main content

Read an episode’s guests from another add-on

Premium Beginner Guest Manager

Show “Featuring…” lines, label transcript speakers or fill an email with an episode’s guests, through the one supported way to read them: never the benecaster_episode_guests table.

benecaster_guest_manager_get_episode_guests() returns the guests linked to an episode, in the episode’s order, each [ 'id' => int, 'name' => string, 'title' => string, 'organization' => string, 'website' => string, 'profile_url' => string ]:

  • id is the guest’s post id; name the guest’s name; title their job or description ('' when not set); organization the organization they are with ('' when not set); website the guest’s own site, http/https only, or ''. To show title and organization as one line, join them as Guest Manager does: Founder, Acme Labs, or whichever is set.
  • profile_url is the guest’s public page: /guests/{slug}/, or /?benecaster_guest_page={slug} under plain permalinks, {slug} being the guest’s slug, which is kept when the guest is renamed.
  • The guest’s private email is never included.
  • It returns [] when the id is not an episode, when the episode has no guests, or when Guest Manager is not on for the episode’s own show. Only published guests are returned.
  • There is no access or status check on the episode: it answers for drafts too. If you show guests to a visitor, decide whether that visitor may see the episode.
  • Values are raw text: escape on output (esc_html(), esc_url()).
  • The function is defined on every request while Guest Manager is active, even when it is off on every show (it then returns []), so function_exists() only has to cover Guest Manager not being installed.
  • Keys may be added in later versions; none will be removed or change meaning.

benecaster_guest_manager_episode_guests filters the list above, ( array $guests, int $episode_id, int $show_id ): array. It runs only when Guest Manager is on for the episode’s show, so nothing can add guests to a switched-off show’s episode. A return that is not an array is ignored.

Code

<?php
// "Featuring Alice Smith and Bob Jones", each linked to their website when they have one.
$guests = function_exists( 'benecaster_guest_manager_get_episode_guests' )
    ? benecaster_guest_manager_get_episode_guests( $episode_id )
    : [];

$names = array_map(
    static fn( array $g ): string => '' !== $g['website']
        ? '<a href="' . esc_url( $g['website'] ) . '">' . esc_html( $g['name'] ) . '</a>'
        : esc_html( $g['name'] ),
    $guests
);

if ( [] !== $names ) {
    echo esc_html__( 'Featuring', 'my-addon' ) . ' ' . wp_sprintf( '%l', $names );
}

View on GitHub →

Hooks Used

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