Skip to main content

benecaster_compare_tiers()

Access Tier Free
benecaster_compare_tiers( int $show_id, string $a, string $b ): ?int

Tells you which of two tiers on a show ranks higher, so an add-on can tell an upgrade from a downgrade. benecaster_subscription_tier_moved carries the old and new slugs but no direction; this supplies it.

Ranking is position in benecaster_get_show_tiers(), lowest first, so position 0 is the lowest tier. It is the same ranking [benecaster_tier_gate] uses, so your add-on agrees with every gate on the site.

Parameters

Name Type Default Required Description
show_id int — Yes The show both tiers belong to.
a string — Yes A tier slug.
b string — Yes The tier slug to compare it with.

Return Value

Type: int|null

1 when $a ranks above $b, -1 when below, 0 when they are the same tier. null when the pair cannot be ranked: an empty slug, the follower slug (a follower is not a tier), a buy-up, a slug the show does not know, or one built-in membership tier and one membership-plugin tier.

Example

add_action( 'benecaster_subscription_tier_moved', function ( int $user_id, int $show_id, string $old, string $new ): void {
    $cmp = benecaster_compare_tiers( $show_id, $new, $old );
    if ( null === $cmp ) {
        return; // cannot rank — do not guess
    }
    my_crm_tag( $user_id, $cmp > 0 ? 'upgraded' : ( $cmp < 0 ? 'downgraded' : 'unchanged' ) );
}, 10, 4 );

Notes

null is not 0. Treat it as "cannot tell" — never as "same tier", and never as an upgrade. A tier deleted since the move is the usual cause.

Never compare slugs, or a stored tier-order value, yourself: the order value is 0 for every tier created in the Memberships admin.

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