Skip to main content

Fire add-on side effects when a show is archived or restored

Free Beginner Since v1.0.0

ShowsController::archive_show() fires benecaster_show_archived( int $show_id ) immediately after the _benecaster_show_archived meta flips to '1'; unarchive_show() fires benecaster_show_unarchived( int $show_id ) symmetrically. The feed returns HTTP 410 for archived shows automatically. Neither action fires on wp_delete_post — archival is soft-delete only. Use standard WP deleted_post filtered on post_type === 'benecaster_show' for permanent deletion.

Code

<?php
add_action( 'benecaster_show_archived', function ( int $show_id ): void {
    // Farewell email to subscribers whose access is about to break.
    $recipients = get_show_subscriber_emails( $show_id );
    wp_mail( $recipients, __( 'Feed archived', 'my-addon' ), '…' );

    // Clear any add-on caches keyed on the show.
    wp_cache_delete( "my_addon_show_{$show_id}", 'my_addon' );
} );

add_action( 'benecaster_show_unarchived', function ( int $show_id ): void {
    // Re-warm caches so the first subscriber poll after restore is fast.
    prime_my_addon_show_cache( $show_id );
} );

View on GitHub →

Hooks Used