Skip to main content

benecaster_registered_token_types

Filter Free

Registers a token type, so core treats an add-on’s listeners correctly everywhere without knowing what the add-on is. There is no setting for this in the podcaster’s admin: it is a developer surface only.

Each entry is keyed by a slug and declares two things: a label (what the listener is called on the Supporter Wall, in badges and on the account page) and behaves_as, the built-in the type inherits every behavioural answer from. behaves_as accepts subscriber or follower only. purchaser is a built-in but not a base, so a descriptor naming it is rejected. There are no per-behaviour overrides: feed resolution, the licence gate, email audiences, promotion and front-end classification all follow the base.

Slugs must be vendor-prefixed (lowercase letters, digits, _ and -, up to 100 characters), which leaves core the whole unprefixed namespace. The filter is add-only. Core re-applies its built-ins afterwards, so a callback can add a type but can never remove or redefine subscriber, follower or purchaser, and a return that is not an array is discarded. Tampering with a built-in, or registering a refused slug, raises _doing_it_wrong() naming the slug so the mistake explains itself.

Counting is not yours to change. A descriptor has no is_paying or exempt field, and the exemption lists are core’s with no filter. A registered type therefore counts toward the plan’s subscriber limit whenever its tier is paid, whatever it behaves like. A follower-like type is non-paying because its tier is free, not because of its base.

Two add-ons registering the same slug cannot be detected. The filter passes an array keyed by slug, so a second callback assigning the same key overwrites the first and core sees one entry. The vendor prefix is the only protection, so choose one that is yours.

A listener whose type is no longer registered, because the add-on was deactivated, is treated as a subscriber and keeps resolving by tier. A slug that matches one of your tier slugs is allowed and is the intended pattern.

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.

<?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 →

Parameters

Name Type Default Description
$types array Registered types, keyed by vendor-prefixed slug, each `[ 'label' => string, 'behaves_as' => 'subscriber'|'follower' ]`. Starts empty: core's built-ins are added after the filter runs.

Returns: array

Example

add_filter( 'benecaster_registered_token_types', function ( array $types ): array {
    $types['transcription-service_patron'] = [
        'label'      => __( 'Patron', 'my-addon' ),
        'behaves_as' => 'subscriber',
    ];
    return $types;
} );

Notes

Register during benecaster_boot. The type is stored in benecaster_tokens.token_type, which is 100 characters wide, so a descriptive vendor prefix fits.

Affects

  • Token\TokenTypeRegistry

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