Skip to main content

Bridge the catalog/entitlement slug split when cross-referencing the two systems

Free Beginner Since v1.0.0

GET /pricing uses short display slugs (e.g. email-editor); the entitlement system uses fully-qualified slugs (e.g. benecaster-addon-email-editor). Pass the wrong form to addon_is_active() and you will silently get false for an add-on the customer actually owns. Use LicenseManager::catalog_slug_to_entitlement_slug() and its inverse whenever you read pricing-catalog data and need to test entitlement. Both helpers are idempotent.

Code

<?php
use Benecaster\License\LicenseManager;

$license = new LicenseManager();
$pricing = get_transient( 'benecaster_pricing_data' );

foreach ( $pricing['addons'] ?? [] as $addon ) {
    $entitlement_slug = LicenseManager::catalog_slug_to_entitlement_slug( $addon['slug'] );
    $owned            = $license->addon_is_active( $entitlement_slug );
    // Render purchase or "owned" UI based on $owned.
}