Skip to main content

benecaster_feed_sync_completed

Action Free

Fires after every feed sync run regardless of outcome — both success and failure. $result is a detailed summary including error_message on failure. Use for monitoring dashboards, external logging, or alerting. Fires on every sync run (manual, on_login, and cron).

It always fires immediately after benecaster_feed_sync_after, on the success path and on both failure paths, so the state described there holds here too: on success the new episode drafts are already written and the show’s feed cache is already cleared. On failure nothing was written and no cache operations occurred. Both hooks are core; neither needs an add-on. Unlike _after, which carries only counts, this one passes the complete result array.

Notify production team on Slack when new episodes found during feed sync

Free Beginner

When Benecaster imports episodes from an existing feed, it does so on a schedule and without saying anything. That is the right default once you trust it — and exactly the wrong one while you are still finding out whether you do.

benecaster_feed_sync_completed runs at the end of every sync and reports what was found, including the created drafts’ IDs. Posting that to Slack gives the team a running account of what is being picked up, which is worth having during a migration, when the question “did it get everything?” is asked daily and answering it by hand means counting episodes. If a count is enough, the lighter benecaster_feed_sync_after( int $show_id, int $drafts_created, int $episodes_new, string $triggered_by ) carries no IDs but is simpler to consume.

<?php
add_action(
    'benecaster_feed_sync_completed',
    function ( array $result ): void {
        if ( 'success' !== $result['status'] || empty( $result['draft_ids'] ) ) {
            return;
        }

        $lines = array_map(
            static fn ( $id ): string => '- ' . get_the_title( (int) $id ),
            $result['draft_ids']
        );

        wp_remote_post( 'https://hooks.slack.com/services/T000/B000/XXXX', [
            'timeout'  => 5,
            'blocking' => false,
            'headers'  => [ 'Content-Type' => 'application/json' ],
            'body'     => wp_json_encode( [
                'text' => sprintf(
                    "*%s*: %d new draft(s) from Feed Sync (%s):\n%s",
                    get_the_title( (int) $result['show_id'] ),
                    count( $result['draft_ids'] ),
                    $result['triggered_by'],
                    implode( "\n", $lines )
                ),
            ] ),
        ] );
    }
);

View on GitHub →

Parameters

Name Type Default Description
$result array Sync result object: {show_id, feed_url, triggered_by, user_id, episodes_found, episodes_new, drafts_created, draft_ids, status, error_message, started_at, completed_at}. draft_ids is the array of created episode post IDs (empty on failure).

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