Skip to main content

Register a token type for a product

Free Intermediate

Give an add-on’s listeners their own token type, so core classifies them correctly everywhere. A token’s type answers who a listener is: one value per person per show. Core ships subscriber, follower and purchaser. Register your own from your benecaster_boot callback and core treats your listeners correctly in the feed, the licence gate, email audiences, promotion and every front-end badge, without knowing what your add-on is.

behaves_as is the whole behavioural contract. Your type inherits every answer from the built-in you name: pick subscriber for listeners resolved by their tier as usual, or follower for ones who should get the public feed and keep the licence-gate exemption. Slugs are vendor-prefixed, lowercase, up to 100 characters.

Give your listeners content by putting them on their own tier, not through this filter. You also cannot change how they are counted: a registered type counts toward the plan’s subscriber limit whenever its tier is paid. If your add-on is deactivated, its listeners’ rows stay and are treated as subscribers, resolved by their tier.

Code

<?php
add_action( 'benecaster_boot', function (): void {
    add_filter( 'benecaster_registered_token_types', function ( array $types ): array {
        $types['my-addon_patron'] = [
            'label'      => __( 'Patron', 'my-addon' ),
            'behaves_as' => 'subscriber',   // or 'follower'
        ];

        return $types;
    } );
} );

View on GitHub →

Hooks Used

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