Skip to main content

benecaster_user_has_active_membership()

Access Tier Free
benecaster_user_has_active_membership( int $show_id, int $user_id = 0 ): ?bool

Whether somebody holds an active membership on a show right now, asked of the show’s membership system, never of their feed token. Any active membership counts, free or paid: trialing, payment retrying, paused and comped members included. A follower is not a member.

Use it to tell a member from a non-member. To find out what a member can open, use benecaster_user_can_access_episode().

Parameters

Name Type Default Required Description
show_id int — Yes The show (post) ID.
user_id int 0 No WordPress user ID. Defaults to the current user when 0 or omitted.

Return Value

Type: bool|null

true when the person holds an active membership on the show, false when they do not, and null when Benecaster cannot tell.

Example

$member = benecaster_user_has_active_membership( $show_id );

if ( true === $member ) {
    echo '<p>Thanks for being a member.</p>';
} elseif ( false === $member ) {
    echo do_shortcode( '[benecaster_subscribe]' );
}
// null: the membership plugin could not answer. Show nothing rather than guess.

Notes

**null means cannot tell: treat it as "take nothing away".** It is returned when the show has no membership system configured, or its membership plugin is inactive. An inactive plugin answers as if nobody were a member, so Benecaster refuses to guess. A show on Benecaster's built-in membership always gets a true or false.

To revoke someone's feed only if this is false, do not check and then revoke. A payment can land in between and cost a payer their feed URL. Call TokenManager::revoke_unless_subscribed(), which does both as one step; see Revoke a listener's feed only if they are not a member.

**Not the same question as benecaster_get_user_tier_for_show().** That reads the feed token, which an import creates on a paid tier before anyone has paid.

Unfiltered, and Preview as Tier does not change its answer.

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