Skip to main content

Read or override the active bridge for a show from an add-on

Premium Intermediate

Each show is connected to one membership system — e.g. MemberPress, WooCommerce Subscriptions — and that connection is what Benecaster calls the show’s bridge. An add-on can both ask which bridge a show is using and set it.

Setting it is the more useful half. An add-on running its own setup wizard can connect the podcaster’s membership plugin as part of the flow, instead of finishing with “now go to Settings and pick your plugin” — which is where guided setups tend to lose people. Reading it is how you skip a step that is already done, or decide which hooks to register.

When to Use This

  • Your add-on has a setup screen that should skip a step if a bridge is already configured

  • You’re building a setup wizard that activates the user’s preferred subscription plugin as part of a guided flow

  • You want to introspect which bridge is active before registering show-specific hooks

  • You’re migrating from one bridge to another and need to switch programmatically

How It Works

Two public functions. Neither needs the container, a class name, or Benecaster to have finished booting.

Readingbenecaster_get_active_bridge_slug( int $show_id ): string returns the slug, or an empty string when the show has no bridge configured. It reads the stored value directly rather than resolving a bridge object, which is why it is safe to call early and why you do not need to know any interface’s shape to branch on it.

Settingbenecaster_set_active_bridge( int $show_id, string $slug ): bool connects a show to a registered bridge, or clears it when passed ''. Always check the return value. A refusal is returned, not thrown: an unregistered slug writes nothing and answers false, so a typo fails loudly instead of leaving a show pointed at a bridge that will never resolve.

The recipe also shows the same two calls behind an add-on’s own REST endpoint, for setup wizards that run in the browser: check the caller is an administrator, sanitise the show and bridge names coming in, and turn a refusal into a proper error response rather than a silent success.

Valid Bridge Slugs

Slug Plugin
memberpress MemberPress
woo-subscriptions WooCommerce Subscriptions
paid-memberships Paid Memberships Pro
restrict-content Restrict Content Pro
benecaster_builtin Built-in Membership

These are the slugs core registers, not the whole set: third-party bridges register through the benecaster_bridges filter, so a site may carry slugs beyond them. Validate by passing the slug to the setter and reading the boolean back, rather than against a hard-coded list of your own. An unregistered slug returns false without modifying the stored value.

Notes

“No bridge” is an empty string. There is no placeholder object to test for and no null to guard against — '' === benecaster_get_active_bridge_slug( $show_id ) is the whole check.

Registered is not the same as installed. The setter checks only that the slug is registered, and core’s bridges are registered whether or not their plugin is present. The available callable on a bridge registration gates what the picker offers, not what the setter accepts. If your wizard needs to know the plugin is really there, check for it yourself — a true from the setter does not tell you.

This is a programmatic override, not a UI action. The bridge picker in Settings → Subscription reflects the stored value. benecaster_set_active_bridge() writes the same post meta — the UI will show the new bridge on next page load.

Related

Code

<?php
$show_id = 42;

// Reading: an empty string means nothing is configured yet.
if ( '' === benecaster_get_active_bridge_slug( $show_id ) ) {
    // Prompt the podcaster, or connect one on their behalf.
    if ( ! benecaster_set_active_bridge( $show_id, 'memberpress' ) ) {
        // Refused: the slug is not registered on this site.
        // Nothing was written — do not report success.
        return new WP_Error(
            'bridge_not_registered',
            __( 'That membership plugin is not available on this site.', 'my-addon' )
        );
    }
}

// Clearing is the empty string, and it always succeeds.
// benecaster_set_active_bridge( $show_id, '' );

View on GitHub →

Hooks Used

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