benecaster_get_token_type()
benecaster_get_token_type( int $token_id ): ?array
Tells you who a token belongs to — a follower, a paying subscriber, a single-purchase listener, or an add-on’s own listener type — for the hooks that pass only a $token_id, such as benecaster_token_generated, benecaster_token_revoked and benecaster_token_reactivated. A revoked token still answers, so it works inside a revocation callback.
Decide behaviour on base, never on type. The set of types is open: an add-on can register a listener type that behaves as a follower, and 'follower' === $type['type'] would treat its listeners as subscribers. Compare type only to recognise a specific type you know — purchaser (bought something outright and holds no subscription; its base is subscriber), or your own add-on’s type.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
token_id |
int |
— | Yes | The token ID a hook passed, such as the first argument of benecaster_token_revoked. |
Return Value
Type:
array|null
array{type: string, base: string, label: string}, or null when no token has that ID. type is the stored type, verbatim — subscriber, follower, purchaser, or a registered add-on type. base is subscriber or follower: what that type behaves as (an add-on type that is no longer registered counts as subscriber). label is the translated display label. Active and revoked tokens both answer.
Example
add_action( 'benecaster_token_generated', function ( int $token_id, int $user_id, int $show_id ): void {
$type = benecaster_get_token_type( $token_id );
if ( null === $type ) {
return;
}
my_esp_add_tag( $user_id, 'follower' === $type['base'] ? 'follower' : 'subscriber' );
}, 10, 3 );
Notes
Not a paying test. Whether a listener counts as paying depends on the type and on whether their tier is free: a subscriber on a free tier is not paying.
For an email lookup, benecaster_get_subscriber_data() returns the same two facts as token_type and token_type_base. Worked example: the recipe Tag a lost listener by why they left.
Need this built rather than just documented? See our services →