Skip to main content

Implement a custom bridge that returns multiple active tiers per user

Premium Advanced

Most membership systems assume one membership per person, and Benecaster’s bridges follow suit: asked which tiers somebody is on, a bridge answers with the one it found. If your membership system allows several at once, that default quietly loses everything but the first.

A bridge can answer with the full list instead. When it does, Benecaster builds the subscriber a feed containing every episode any of their tiers entitles them to, rather than making them choose. This recipe covers what a bridge has to implement for that to work, and the traps in getting the list right.

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 →

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