Skip to main content

NativeBridge

\Benecaster\Bridge\Bridges\NativeBridge

Class Premium

The built-in membership bridge. Implements BridgeInterface against Benecaster’s own subscription and membership tier records — read through SubscriptionRepository and MembershipTierRepository — rather than a third-party plugin. Plugin slug: benecaster_builtin.

Available on all plans.

NativeBridge is registered and activated automatically by BridgeManager — you do not instantiate it directly. Activate the built-in bridge by selecting it in the bridge picker after the activation gate conditions are met (a Stripe keyset saved for the site or any show, and at least one active tier). The gate is evaluated by NativeBridgeActivationGate.

Custom code that hooks into benecaster_subscription_activated, benecaster_token_generated, and other lifecycle actions fires for built-in membership subscribers exactly as it fires for external-bridge subscribers — no code changes required.

Methods

Method Visibility Since Description
get_user_tier( int $user_id, int $show_id ): ?string Public — Resolves the subscriber's active subscription via SubscriptionRepository. Returns the active tier slug, or null if no active subscription exists.
get_all_user_tiers( int $user_id, int $show_id ): array Public — Returns all active tier slugs for the user. Built-in membership supports one active tier per user per show — returns a single-element array or [].
is_user_active( int $user_id, int $show_id ): bool Public — Delegates to get_user_tier().
get_all_tiers( int $show_id ): array Public — Reads the show's membership tiers via MembershipTierRepository. Returns all active tiers as array{id: int, name: string, price: float|null}. price is the monthly price (or annual if monthly is not set).
dispatch_activation( int $user_id, int $show_id, string $tier_slug, string $source = 'new' ): void Public — Invokes every callback registered via on_subscription_activated(). SubscriptionListener::handle_activation() is the first registered consumer and drives token generation and the welcome email.
dispatch_change( int $user_id, int $show_id, string $old_tier_slug, string $new_tier_slug ): void Public — Invokes every callback registered via on_subscription_changed(). SubscriptionListener::handle_tier_change() updates the token row before firing benecaster_subscription_tier_changed.
dispatch_renewal( int $user_id, int $show_id ): void Public — Invokes every callback registered via on_subscription_renewed() and fires benecaster_subscription_renewed.
create_manual_membership( int $user_id, int $show_id, string $tier_slug, ?string $expiry_at ): array Public — Implements BridgeInterface::create_manual_membership(). Creates the built-in subscription and its token. Returns { subscription_id: int, token_prefix: string }.
set_subscription_manager_factory( callable $factory ): void Public — Receives a lazy resolver for the plugin's subscription service, called from Plugin.php container wiring to avoid a circular constructor dependency.

Hooks Fired

Notes

on_subscription_activated(), on_subscription_changed(), and on_subscription_renewed() store and invoke the callbacks registered through them. A callback registered here fires.

on_subscription_cancelled() and on_payment_failed() remain no-ops — those paths route through routing actions and InvoicePaymentFailedListener / SubscriptionDeletedListener directly.