Skip to main content

Clear a retired sale’s access before moving an episode

Free Intermediate

Benecaster refuses to move an episode to another show while it carries access under a name that is none of its show’s tiers, public, the follower slug or a buy-up’s. That is how a standalone sale reaches an episode, and also what a retired one leaves behind. Benecaster can’t tell which is which, so it never removes one by itself.

A plugin that sold episodes, and knows a product is retired for good, can clear its own entries through the same route the Access tab’s Other Access → Remove uses: DELETE /benecaster/v1/episodes/{id}/unrecognised-availability/{slug}. The route refuses any tier, public, follower or buy-up slug with 400, so it can’t be used to strip a tier date. See the Episodes REST API reference.

Code

<?php
function my_store_clear_retired_product( int $episode_id, string $grant_slug ): bool {
    $get   = rest_do_request( new WP_REST_Request( 'GET', "/benecaster/v1/episodes/{$episode_id}" ) );
    $slugs = array_column( $get->get_data()['unrecognised_availability'] ?? [], 'slug' );
    if ( ! in_array( $grant_slug, $slugs, true ) ) {
        return false; // Not there, or a tier/buy-up slug the route would refuse.
    }

    $route = "/benecaster/v1/episodes/{$episode_id}/unrecognised-availability/" . rawurlencode( $grant_slug );
    return 200 === rest_do_request( new WP_REST_Request( 'DELETE', $route ) )->get_status();
}

View on GitHub →

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