Skip to main content

Perform a community action on episode publish

Free Intermediate Since v1.0.0

CommunityPlatformRegistry calls onEpisodePublished() on every registered, configured platform when benecaster_episode_published fires. Implement this method to create a discussion thread, post an announcement, pin a notification, or update a community calendar. The Circle built-in implementation — shown in the code — is the canonical example: it reads a per-episode override mode, creates a Circle post, and stores the URL as a merge tag.

Code

<?php
// Circle's built-in onEpisodePublished() — canonical example.
public function onEpisodePublished( int $episode_id, int $show_id ): void {
    if ( ! $this->isConfigured() ) { return; }

    $mode     = get_post_meta( $episode_id, '_benecaster_circle_discussion_mode', true ) ?: 'default';
    $globally = (bool) get_option( 'benecaster_circle_auto_discussion' );

    if ( $mode === 'skip' || ( $mode === 'default' && ! $globally ) ) { return; }

    $space_id = get_post_meta( $episode_id, '_benecaster_circle_discussion_space', true )
                ?: get_option( 'benecaster_circle_episode_discussion_space' );
    if ( ! $space_id ) { return; }

    $post_url = $this->client->createPost(
        $space_id,
        get_the_title( $episode_id ),
        get_post_meta( $episode_id, '_benecaster_description_rss', true )
    );

    if ( $post_url ) {
        update_post_meta( $episode_id, '_benecaster_circle_discussion_url', $post_url );
    }
}

View on GitHub →

Hooks Used