Skip to main content

AddonActivationController

\Benecaster\REST\AddonActivationController

Class Free

Serves the per-show add-on activation controls on Settings → Add-ons, over GET|POST benecaster/v1/addons/activation.

GET returns one row per published show; POST applies one change and returns the rebuilt row set, so the screen renders confirmed server state rather than its own optimistic guess.

Constructor Dependencies

Type Description
\Benecaster\License\LicenseManager Resolves the grant half per show.
\Benecaster\License\ShowAddonRepository Reads and writes the local activation layer.

Methods

Method Visibility Since Description
index(): WP_REST_Response Public GET handler. One row per published show: id, uuid, title, granted[], disabled[].
update( WP_REST_Request $request ): WP_REST_Response Public POST handler taking show_id, addon_slug, enabled. ⚠ Writes the activation layer only — it never touches an entitlement and never calls the licence server. ⚠ A slug the show's licence does not grant is refused with 400 addon_not_granted rather than stored. Fires benecaster_addon_activation_changed on success.
build_show_rows( LicenseManager $license, ShowAddonRepository $show_addons ): array Builds the row set. ⚠ Deliberately public staticAdminMenu calls it to seed benecasterAdmin.addonShows on first paint, so the initial render and the post-save refetch cannot drift into disagreeing about the payload shape. Two builders would be two shapes, and the bug would appear only after a save.

Hooks Fired

Notes

Both routes require manage_options plus a valid wp_rest nonce.

Why an ungranted slug is refused rather than stored. A silent off recorded against an add-on the licence does not grant becomes indistinguishable from a deliberate choice on the day the licence does grant it — so the customer would buy an add-on and find it already switched off, with nobody having switched it off.

The grant list comes from the pricing catalog, which is the only list of add-ons the plugin knows about — there is no local registry. An install whose pricing transient has not been fetched yet reports no grants, which is correct rather than unfortunate.