Skip to main content

ShowAddonRepository

\Benecaster\License\ShowAddonRepository

Class Free

Storage for per-show add-on state. The two layers it deliberately keeps apart are the documentation — confusing them is how an entitlement gets destroyed by a UI toggle.

Layer 1 — the GRANT cache (benecaster_show_addons_{show_uuid}): a local read-only mirror of what the licence grants, written only by LicenseValidationCron from the shows[] array on /validate. Nothing else may write it.

Layer 2 — the local ACTIVATION set (benecaster_show_addons_disabled_{show_uuid}): the podcaster’s own on/off choices. It stores only what they switched OFF, so absence means on — which is why a newly granted add-on needs no migration and arrives switched on.

Constructor Dependencies

Type Description
\Benecaster\License\ShowTokenRepository Resolves a show post ID or UUID to the show UUID the options are keyed on. Defaulted.

Methods

Method Visibility Since Description
resolve_show_uuid( int|string $show_context ): string Public Normalises a show post ID or UUID to the UUID both option families are keyed on. Returns '' when it cannot resolve one.
has_granted_addons( int|string $show_context ): bool Public Whether a per-show grant cache exists at all for this show. ⚠ This is the cache exists question, distinct from the cache is empty — the caller uses it to decide whether to fall through to the site-wide list.
get_granted_addons( int|string $show_context ): array Public The cached grant list for a show.
set_granted_addons( string $show_uuid, array $addon_slugs ): void Public Written only by LicenseValidationCron. This is a mirror of the licence server's answer; anything else writing it is inventing an entitlement.
is_enabled_for_show( string $addon_slug, int|string $show_context ): bool Public The podcaster's local switch alone — absence means on. This answers only half the question; LicenseManager::addon_is_active() is what combines it with the grant.
set_enabled_for_show( string $show_uuid, string $addon_slug, bool $enabled ): void Public Records a switch-off, or removes one. ⚠⚠ Turning an add-on off must never alter an entitlement — this writes the disabled set and never the grant cache, pinned by test_switching_an_addon_off_never_writes_to_the_grant_cache().
get_disabled_addons( int|string $show_context ): array Public The slugs the podcaster has switched off for this show.
delete_show_addons( string $show_uuid ): void Public Removes both layers for a show. Called when a show's licence is disconnected — the grant cache is meaningless without a token, and a surviving activation set would silently re-apply on reconnect.

Constants

Name Value Description
OPT_GRANTED_PREFIX 'benecaster_show_addons_' Prefix for the grant cache option, one option per show.
OPT_DISABLED_PREFIX 'benecaster_show_addons_disabled_' Prefix for the local switch-off set, one option per show.

Notes

⚠⚠ Turning an add-on off is not revoking it. The customer still owns the add-on and is expected to switch it back on. Code that treats a switch-off as a revocation — deleting authored data rather than a per-show cache — destroys something the customer still pays for, and the next switch-on cannot undo a delete.

Why absence means on. Storing only the switch-offs means a newly granted add-on is active the moment the grant arrives, with no migration and no backfill. Storing the switched-on set instead would require writing a row for every show every time a licence gained an add-on, and any missed write would silently disable a paid feature.

One option per show follows the ShowTokenRepository precedent. Both options are non-autoloaded.