Skip to main content

RestrictContentBridge

Benecaster\Bridge\Bridges\RestrictContentBridge

The built-in bridge for Restrict Content Pro. Connects Benecaster to RCP subscription levels, mapping each level to a Benecaster tier.

Slug: restrict-content
Detection: defined('RCP_PLUGIN_VERSION') — true when Restrict Content Pro is active.
Minimum version: RCP 3.0 or higher is required. RCP 3.0 introduced rcp_get_customer_from_user_id(), which this bridge uses for tier resolution. Sites running RCP 2.x will not see this bridge in the subscription plugin picker.

Tier Resolution

get_user_tier( int $user_id, int $show_id ) works as follows:

  1. Calls rcp_get_customer_from_user_id( $user_id ) to retrieve the RCP_Customer object for the user.
  2. Calls get_memberships( ['status' => 'active'] ) on that customer to retrieve all active membership objects.
  3. For each active membership, reads its subscription level ID.
  4. Looks up a matching row in benecaster_tier_map where plugin_slug = 'restrict-content' and external_tier_id matches the level ID.
  5. Filters to rows where show_id matches the given $show_id.
  6. Returns the internal_tier_slug of the first matching row, or null if none matches.

If rcp_get_customer_from_user_id is unavailable (RCP < 3.0), get_user_tier() returns null unconditionally.

Required setup: At least one row must exist in benecaster_tier_map with plugin_slug = 'restrict-content' and external_tier_id matching an RCP subscription level ID. Without a mapped row, get_user_tier() always returns null. See Mapping Your Membership Tiers.

Tier Listing

get_all_tiers( int $show_id ) returns all subscription level objects via rcp_get_subscription_levels(). The $show_id parameter is accepted but not used. Returns [] if rcp_get_subscription_levels is unavailable. Each entry is array{id: int, name: string, price: float}, where id is the level ID as an integer, name is the level name, and price is the level’s price field. A price of 0.00 marks the tier as free — it will not count toward the Benecaster license tier limit.

Tier Save Events

on_tier_saved() hooks into RCP’s subscription level save pipeline. RCP provides separate hooks for creating and updating levels — both should be wired to the same callback. Specific hook names TBD — verify against RCP docs before implementation (candidates: rcp_add_subscription_level for creation, rcp_update_subscription_level for updates). Fires the callback with array{id: int, name: string, price: float} where price is read from the level’s price field.

RCP Hooks

RestrictContentBridge uses two RCP hooks. One handles activation, cancellation, and expiry via status transitions; the other handles renewals.

RCP hook Condition Bridge event Notes
rcp_transition_membership_status new_status = 'active' on_subscription_activated Membership activated. old_status = 'pending' → source 'new'; any other old status → source 'resubscribe'.
rcp_transition_membership_status new_status = 'cancelled' on_subscription_cancelled Membership cancelled deliberately by subscriber or admin.
rcp_transition_membership_status new_status = 'expired' on_subscription_cancelled Membership reached its end date without renewal.
rcp_membership_post_renew on_subscription_renewed Successful recurring payment; period extended. Receives $membership_id, $membership.
(none) on_payment_failed No-op — see known limitation below.

on_subscription_changed() is a documented no-op. RCP has no dedicated level-change hook; level changes arrive as a cancellation of the old membership followed by a new activation, each routing through rcp_transition_membership_status.

Known Limitations

No universal payment failure hook. RCP has no hook that fires across all payment gateways when a recurring payment fails. on_payment_failed is a documented no-op — it registers no hooks and never fires. Failed payments eventually cause RCP to transition the membership to 'expired' via rcp_transition_membership_status, which fires on_subscription_cancelled. This provides eventual consistency: feed access is not immediately revoked on payment failure, but is revoked once RCP expires the membership through its own retry logic. For fine-grained failure tracking, hook directly into the active gateway’s failure event via rcp_gateway_* hooks.

No native level-change event. RCP has no dedicated hook for switching between subscription levels. on_subscription_changed() is a documented no-op. Level changes resolve as a cancellation of the old membership and activation of the new one, each firing the respective callbacks. benecaster_subscription_tier_changed is not fired in this flow.

Setup Notes

No custom code is needed to use RestrictContentBridge. It is configured, connected, and tested entirely through the Benecaster admin interface.

See Restrict Content Pro Setup for the complete setup walkthrough, including version requirements, how to connect the bridge, map subscription levels to tiers, and test the connection.