Skip to main content

Classes Reference

Benecaster exposes a small set of public PHP classes that your code can implement, extend, or interact with. These are the extension points for code that needs to go beyond what hooks and filters provide.

Public Classes

Class Description
Benecaster\License\LicenseManager License state, tier checks, and referral data access
Benecaster\Bridge\BridgeInterface The interface all subscription bridges must implement
Benecaster\Bridge\BridgeManager Bridge detection, activation, and lookup
Benecaster\Bridge\NullBridge Safe fallback returned when no bridge is configured
Benecaster\Bridge\Bridges\MemberPressBridge Reference bridge implementation for MemberPress
Benecaster\Bridge\Bridges\WooSubscriptionsBridge Bridge for WooCommerce Subscriptions
Benecaster\Bridge\Bridges\PaidMembershipsBridge Bridge for Paid Memberships Pro
Benecaster\Bridge\Bridges\RestrictContentBridge Bridge for Restrict Content Pro

LicenseManager

Benecaster\License\LicenseManager is the central class for reading license state and plan-related data from the plugin’s option cache. All values are sourced from the locally cached /validate response — no HTTP call is made per method invocation.

Retrieve the instance via the service container or the benecaster_boot action:

add_action( 'benecaster_boot', function( \Benecaster\Container $container ): void {
    $license = $container->make( \Benecaster\License\LicenseManager::class );
    if ( $license->is_premium() ) {
        // premium logic
    }
} );

For simple checks in add-on code, the corresponding standalone convenience functions (benecaster_is_premium(), benecaster_get_referral_code(), etc.) resolve the container for you.

Public Methods

Method Return Description
is_premium(): bool bool true when a valid paid license is active
addon_is_active(string $slug): bool bool true when the named add-on is licensed and active
is_upgrade_required(): bool bool true when the cached /validate response carries upgrade_required: true (Launch plan at 10-subscriber cap)
get_next_renewal_date(): ?string ?string ISO 8601 date string of the next billing renewal, or null for Launch/Free and unactivated installs
resolve_plan_label(string $slug): string string Human-readable plan name for a slug (e.g. "growth""Growth"); falls back to title-casing the slug if the pricing catalog is unavailable
resolve_addon_label(string $slug): string string Human-readable add-on name for a slug; same fallback as resolve_plan_label()
get_checkout_url(): ?string ?string Cached checkout_url from the /validate response when upgrade_required: true; null when absent (pre-feature license server, no upgrade pending, unactivated)
get_referral_code(): ?string ?string 32-char alphanumeric referral code, or null when the license server has not yet supplied one
get_referral_link(): ?string ?string Full referral URL (https://benecaster.com/ref/{code}), or null when unavailable
get_referral_credit_cents(): int int Pending referral credit in cents; 0 when no credit is available

Referral methods return null / 0 until the license server’s feature/referral-program batch ships and /validate responses begin carrying the referral fields. Guard your add-on UI on the presence of a code before rendering referral copy.

The Bridge System

The bridge system is the abstraction layer between Benecaster and external subscription plugins. When Benecaster needs to know whether a user is subscribed, what tier they’re on, or when a subscription event has occurred, it asks the bridge. The bridge translates those questions into whatever API calls, database queries, or hook registrations the underlying plugin requires.

This design keeps Benecaster’s core independent of any specific membership plugin. The core never imports MemberPress classes, calls WooCommerce functions, or queries membership tables directly — it only calls bridge methods. That independence means the same core code works identically regardless of which membership plugin a site uses, and new plugins can be supported by implementing a single interface.

The classes above form the complete public surface of the bridge system. BridgeInterface defines the contract every bridge must satisfy. BridgeManager tracks which bridges are available and which one is active for each show. NullBridge is a safe no-op stand-in for when no bridge is configured, eliminating the need for null-checks throughout core. The five built-in bridge classes cover the five supported membership plugins; MemberPressBridge is also the canonical reference implementation to read when building a custom bridge.

Custom bridges can be built by implementing BridgeInterface in your own plugin and registering via the benecaster_boot action. The bridge picker UI does not auto-discover third-party bridges — custom bridges are activated programmatically using BridgeManager::set_active_bridge(). See Implement a Custom Bridge for a complete walkthrough.

Class Pages