MemberPressBridge
\Benecaster\Bridge\Bridges\MemberPressBridge
The built-in bridge for MemberPress and the canonical reference implementation for custom bridge development. Slug: memberpress. Detection: class_exists('MeprUser'). Tier resolution queries MeprUser::active_product_subscriptions('ids') and looks up matches in the show’s tier mapping — first match wins. Activation is keyed on MemberPress recording a payment, never on the checkout form being submitted. on_subscription_changed() is a documented no-op: a move inside an upgrade-path Group arrives as an activation of the new membership while the token is still active, which moves the tier and fires benecaster_subscription_tier_moved; MemberPress cancels the old subscription silently.
Implements BridgeInterface and BridgeWritable, and uses ManualMembershipUnsupportedTrait — create_manual_membership() always throws BadMethodCallException; MemberPress has no way to grant a membership without a real transaction. The full method contract is documented once on BridgeInterface and BridgeWritable; the table below covers only what this implementation does differently.
Constructor Dependencies
| Type | Description |
|---|---|
TierMapRepository |
Resolves MemberPress product IDs to Benecaster internal tier slugs, scoped per show. |
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
get_plugin_slug(): string |
Public | — | Returns 'memberpress'. |
get_user_tier( int $user_id, int $show_id ): ?string |
Public | — | Iterates the user's active MemberPress product subscriptions (MeprUser::active_product_subscriptions('ids')) and returns the tier slug of the first one whose tier-map row targets $show_id, or null if none match. |
get_all_user_tiers( int $user_id, int $show_id ): array |
Public | — | Same iteration as get_user_tier(), but collects every matching tier slug instead of stopping at the first — a user with two MemberPress products mapped to the same show gets both. |
is_user_active( int $user_id, int $show_id ): bool |
Public | — | true when get_user_tier() returns non-null. |
get_all_tiers( int $show_id ): array |
Public | — | Returns every published memberpressproduct post as a candidate tier ({id, name, price}). $show_id is accepted for interface compatibility but unused — MemberPress products are site-wide. Price is read from the _mepr_product_price post meta and is null when that meta is absent. |
on_subscription_activated( callable $callback ): void |
Public | — | Registers on mepr-event-transaction-completed for a one-off membership's completed transaction or a subscription's first completed payment (source 'new'; a renewal is not an activation), on mepr-sub-created for a free trial once MemberPress grants the membership (source 'new'), and on mepr-event-subscription-resumed (source 'resumed', MemberPress's own voluntary pause/resume feature — not a payment recovery). Never on mepr-signup, which fires before payment. Calls $callback( $user_id, $show_id, $tier_slug, $source ). |
on_subscription_cancelled( callable $callback ): void |
Public | — | Registers on mepr-event-subscription-stopped (SubscriptionEndReason::CANCELLED) and mepr-event-transaction-expired (SubscriptionEndReason::EXPIRED — a renewal that ran out). Calls $callback( $user_id, $show_id, $reason ). |
on_subscription_changed( callable $callback ): void |
Public | — | No-op. A move inside an upgrade-path Group arrives as the new membership's activation while the token is still active, which moves the tier; MemberPress cancels the old subscription silently, so no cancellation callback fires. A membership outside an upgrade-path Group is held alongside the old one, and cancelling the old one later is a real cancellation of one of several tiers. |
on_subscription_renewed( callable $callback ): void |
Public | — | Registers on mepr-event-transaction-completed, filtered to transactions of an existing subscription after its first payment, so the first payment (an activation) isn't double-counted as a renewal. |
on_payment_failed( callable $callback ): void |
Public | — | Registers on mepr-event-subscription-paused, which MemberPress fires once its retry grace period elapses without a successful charge. |
on_tier_saved( callable $callback ): void |
Public | — | Registers on save_post_memberpressproduct (revisions and autosaves skipped) and calls $callback with the saved product's {id, name, price}. |
register_admin_hooks(): void |
Public | — | Not part of BridgeInterface — called by Plugin.php at boot for any bridge that defines it. Adds a metabox to the MemberPress product edit screen that maps the product to a Benecaster tier per show, and persists the selection to the tier map on save. |
can_import(): bool |
Public | — | true when MeprTransaction exists — always true while MemberPress is active, since that class is core to the plugin. |
create_member( string $email, int $user_id, int $tier_id, array $meta = [] ): bool |
Public | — | Grants an active membership by writing a $0 'complete' MeprTransaction directly — MemberPress determines active membership from the most recent complete transaction per product, so no real charge or gateway call happens. Flagged gateway = 'manual' with a Benecaster source tag so migrated rows are auditable. |
supports_tier( int $tier_id ): bool |
Public | — | true when $tier_id resolves to a real, existing memberpressproduct post. |
create_manual_membership( int $user_id, int $show_id, string $tier_slug, ?string $expiry_at ): array |
Public | — | Inherited from ManualMembershipUnsupportedTrait — always throws BadMethodCallException. MemberPress has no API for creating an active membership without a real transaction. |