Skip to main content

benecaster_find_audience_user_ids()

Membership Free
benecaster_find_audience_user_ids( int $show_id, string $audience ): array

Resolves a broadcast audience slug to the WordPress user IDs it reaches — the public entry point for answering “who would this send go to?” without pulling anything out of the service container.

Built-in audiences:

  • paying — paying subscribers only, the same definition as
    benecaster_count_paying_subscribers(): a token type core doesn’t exempt (PAYING_EXEMPT_TOKEN_TYPES, follower today — a deny list, not token_type = 'subscriber') on a tier that isn’t free. Excludes followers and bridge members on a free tier; includes any other token type, including one an add-on defines, on a paid tier.

  • followers — direct followers only.

  • all — every active token holder for the show.

  • tier:SLUG — active holders of one tier, e.g. tier:gold.

A tier: slug must match one of the show’s configured tier slugs exactly, and the match is case-sensitive. tier:Gold does not find gold.

tier:follower does not reach your followers. Follower tokens carry the tier slug follower, which is not a tier-map entry on a normal install, so it resolves empty. Use followers.

Anything else resolves to an empty array before the benecaster_broadcast_audience_user_ids filter fires, which is how an add-on defines an audience of its own — the callback receives an empty list and returns whatever it likes. The filter runs for built-in audiences too, so a callback can equally subtract from one: opt-outs, suppression lists, a test-group restriction.

Parameters

Name Type Default Required Description
show_id int Yes WordPress post ID of the show.
audience string Yes Audience slug: paying, followers, all, tier:SLUG, or a slug an add-on defines.

Return Value

Type: array

Deduplicated WordPress user IDs. Order is not guaranteed. Empty for an audience nobody is in, and for one that does not exist.

Example

$gold = benecaster_find_audience_user_ids( $show_id, 'tier:gold' );

foreach ( $gold as $user_id ) {
    // Hand off to the email queue, an ESP API call, an export sheet.
}

Hooks Fired

Notes

An empty array is not an error, and is never distinguishable from one. A tier nobody holds, a slug the show has not configured, a typo, and an audience whose members were all revoked this morning all return []. A caller that needs to tell those apart has to check the tier map itself — so do not report "no subscribers on that tier" on the strength of this return value alone, because a mistyped slug looks exactly the same.

Safe to call from inside a benecaster_broadcast_audience_user_ids callback. Asking for the audience you are currently resolving returns core's own answer rather than recursing; asking for a different one filters normally.

Unsubscribe suppression is applied separately, further down the send path. A user ID in this list is not a promise that the person will receive the email.

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