Skip to main content

Implement a custom bridge that returns multiple active tiers per user

Free Advanced Since v1.0.0

BridgeInterface::get_all_user_tiers() returns all tier slugs a user is active on for a given show. The default implementation wraps get_user_tier() and returns a single-element array. Override it when subscribers can hold multiple memberships simultaneously — FeedController calls this at feed delivery time and assembles the union of matching tier feeds.

Code

<?php
class MyCustomBridge implements \Benecaster\Bridge\BridgeInterface {
    public function get_all_user_tiers( int $user_id, int $show_id ): array {
        $slugs = [];
        foreach ( my_plugin_get_user_memberships( $user_id ) as $membership ) {
            $tier = $this->tier_map->find_by_external( 'my-plugin', (string) $membership->level_id );
            if ( $tier && (int) $tier->show_id === $show_id ) {
                $slugs[] = $tier->internal_tier_slug;
            }
        }
        return $slugs;
    }
    // ... other BridgeInterface methods
}

View on GitHub →