Skip to main content

Invalidate an external cache or CDN when an episode is unpublished

Free Beginner Since v1.0.0

Fires when an episode leaves ‘publish’ — whether trashed, reverted to draft, or set to private. Pair with benecaster_episode_published to keep external CDN caches and search indexes in sync with episode visibility state. Does NOT fire on trash — for that, check the status transition inside this hook.

Code

<?php
add_action( 'benecaster_episode_unpublished', function ( int $episode_id, int $show_id ) {
    // Purge the episode's CDN cache so the locked-content page is served.
    my_cdn_purge_url( get_permalink( $episode_id ) );

    // Remove from search index.
    my_search_index_delete( $episode_id );
}, 10, 2 );

View on GitHub →

Hooks Used