PaidMembershipsBridge
\Benecaster\Bridge\Bridges\PaidMembershipsBridge
The built-in bridge for Paid Memberships Pro. Slug: paid-memberships. Detection: defined('PMPRO_VERSION'). Minimum version: PMP 2.0. Routes all membership lifecycle events through a single pmpro_after_change_membership_level hook, distinguishing event types by argument values. on_subscription_changed() is a documented no-op — a level change arrives as an activation of the new level on the still-active token, which moves the tier and fires benecaster_subscription_tier_moved. Payment failure coverage is gateway-dependent.
Implements BridgeInterface and BridgeWritable, and uses ManualMembershipUnsupportedTrait — create_manual_membership() always throws. 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 PMP membership level IDs to Benecaster internal tier slugs, scoped per show. |
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
get_plugin_slug(): string |
Public | — | Returns 'paid-memberships'. |
get_user_tier( int $user_id, int $show_id ): ?string |
Public | — | Iterates pmpro_getMembershipLevelsForUser() (PMP 2.0+) and returns the tier slug of the first level whose tier-map row targets $show_id, or null if none match or the function is unavailable (PMP < 2.0). |
get_all_user_tiers( int $user_id, int $show_id ): array |
Public | — | Same iteration as get_user_tier(), but collects every matching tier slug — a user holding two PMP levels 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 PMP membership level from pmpro_getAllLevels() as a candidate tier ({id, name, price}). $show_id is accepted for interface compatibility but unused — PMP levels are site-wide. Returns [] when pmpro_getAllLevels() is unavailable. |
on_subscription_activated( callable $callback ): void |
Public | — | Registers on pmpro_after_change_membership_level, filtered to level_id > 0 with cancel_level_id !== level_id (a grant, not a same-level renewal). source is 'new' when cancel_level_id is 0, 'resubscribe' otherwise. |
on_subscription_cancelled( callable $callback ): void |
Public | — | Registers on pmpro_after_change_membership_level with level_id === 0, which covers both explicit cancellation and unrenewed expiry. Distinguishes the two via an internal flag set between pmpro_membership_pre_membership_expiry and _post_membership_expiry — a change inside that bracket reports SubscriptionEndReason::EXPIRED, otherwise CANCELLED. |
on_subscription_changed( callable $callback ): void |
Public | — | No-op. PMP has no dedicated plan-change event — a level change reaches Benecaster as an activation of the new level on the still-active token, which moves the tier and fires benecaster_subscription_tier_moved. |
on_subscription_renewed( callable $callback ): void |
Public | — | Registers on pmpro_after_change_membership_level, filtered to level_id > 0 with cancel_level_id === level_id — PMP's signature for re-granting the same level. Autorenewals that only extend expiry without calling pmpro_changeMembershipLevel() do not fire this. |
on_payment_failed( callable $callback ): void |
Public | — | Registers on pmpro_subscription_payment_failed, fired from PMP's gateway IPN handlers. Coverage is gateway-dependent — confirmed for Stripe and PayPal Express; other gateways may not fire it. |
on_tier_saved( callable $callback ): void |
Public | — | Registers on pmpro_save_membership_level and calls $callback with the level re-fetched via pmpro_getLevel() as {id, name, price}. |
register_admin_hooks(): void |
Public | — | Not part of BridgeInterface — called by Plugin.php at boot for any bridge that defines it. Renders a per-show tier dropdown on the PMP level edit screen (pmpro_membership_level_after_other_settings) and persists the selection on pmpro_save_membership_level. |
can_import(): bool |
Public | — | true when pmpro_changeMembershipLevel() and pmpro_getLevel() both exist. |
create_member( string $email, int $user_id, int $tier_id, array $meta = [] ): bool |
Public | — | Grants the level via pmpro_changeMembershipLevel( $tier_id, $user_id ) — the same call PMP's own admin 'Change Membership Level' action uses. No order or invoice record is created. |
supports_tier( int $tier_id ): bool |
Public | — | true when $tier_id resolves to a real PMP level via pmpro_getLevel(). |
create_manual_membership( int $user_id, int $show_id, string $tier_slug, ?string $expiry_at ): array |
Public | — | Inherited from ManualMembershipUnsupportedTrait — always throws BadMethodCallException. |