Skip to main content

Sell episode access from your own add-on, without storing it in Benecaster

Free Intermediate

There are two ways to give a listener access that is not part of their tier, and choosing between them is the first decision an add-on developer makes. Grant episode access from an add-on records the grant in Benecaster’s own table. Use this filter instead when your add-on already knows who bought what (an existing store, a licence server, a membership product of your own) and you would rather answer the question than duplicate the data.

Each slug still needs availability rows, exactly as in the other recipe: the filter says who is entitled and the availability rows say to what. A slug with no rows resolves fine and carries nothing.

Everything returned is owned outright. It survives an over-limit demotion, a licence grace period and the end of the listener’s membership, so do not use this filter for access that should end when a membership ends. That is what a buy-up is. The filter is add-only: core’s own rows are merged back in after your callback, so removing a slug does nothing. It runs on every authenticated feed request, so keep the callback to an indexed lookup rather than an HTTP call.

Code

<?php
add_filter(
    'benecaster_entitlement_grant_slugs',
    function ( array $slugs, int $user_id, int $show_id ): array {
        // Your own record of what this person owns on this show. Return the
        // NAMED sets they are entitled to — a product or a bundle — never a
        // per-person list of episode IDs.
        foreach ( my_addon_products_owned( $user_id, $show_id ) as $product_slug ) {
            $slugs[] = $product_slug;
        }

        return $slugs;
    },
    10,
    3
);

View on GitHub →

Hooks Used

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