Skip to main content

benecaster_bridges

Filter Premium

Registers subscription bridges — the connection between a show and the membership plugin that owns its subscribers. Benecaster ships four (MemberPress, WooCommerce Subscriptions, Paid Memberships Pro, Restrict Content Pro); this filter is how a third party adds a fifth, and until it existed there was no way to.

Each entry is keyed by bridge slug and carries:

  • name (string) — display name shown in the bridge picker. Falls back to the slug when empty.
  • class (class-string) — a BridgeInterface implementation.
  • available (?callable) — optional. Returns true when the bridge should be offered in the picker.

Applied lazily on first read, after benecaster_boot, so hooking during boot is early enough.

Parameters

Name Type Default Description
$bridges array Keyed array of bridge registrations: slug => [ 'name' => string, 'class' => class-string, 'available' => ?callable ].

Returns: array

Example

add_filter( 'benecaster_bridges', function ( array $bridges ): array {
    $bridges['my-membership'] = [
        'name'      => __( 'My Membership Plugin', 'my-addon' ),
        'class'     => \MyAddon\MyMembershipBridge::class,
        'available' => fn (): bool => class_exists( '\\MyMembership\\Plugin' ),
    ];

    return $bridges;
} );

Notes

An absent available means the bridge is always listed. That is the deliberate contract for third-party bridges, which have no equivalent of core's per-plugin detection and would otherwise be permanently hidden. Supply one only if you can answer the question honestly.

Registered is not the same as installed, and benecaster_set_active_bridge() only checks registration. The available callable gates what the picker offers, not what the setter accepts — a slug registered here can be set on a show whether or not its plugin is present. If that matters to your flow, check for the plugin yourself.

Two different failure modes, and only one of them is loud. An entry with no usable class string is discarded — a malformed registration must not make a show's bridge unresolvable, so it is dropped rather than stored. But an entry whose class is a well-formed string naming a class that does not exist registers successfully and then resolves to NullBridge at use time: the slug is accepted, the picker offers it, and every subscriber lookup quietly answers "no". Check your class string against a real autoloaded class, not just against being non-empty.

Affects

  • Settings → Subscription bridge picker
  • benecaster_set_active_bridge() slug validation

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