Skip to main content

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

Premium Beginner

Benecaster names add-ons two different ways, and the two do not match. The pricing catalogue — what the marketing site and the in-plugin add-on browser display — uses a short name like email-editor. The licensing system, which decides what a customer is actually entitled to use, uses a longer one like benecaster-addon-email-editor.

Why this matters. The mismatch fails quietly, which is the dangerous part. Ask the entitlement check whether the customer owns email-editor and it answers no — not because they do not own it, but because nothing by that name exists on that side of the fence. There is no error and no warning. A paying customer simply loses access to an add-on they bought, and the bug looks like a licensing fault rather than a naming one.

Any code that reads from the pricing catalogue and then tests entitlement has to cross that line, so translate the name at the boundary rather than assuming the two agree. Benecaster provides a helper in each direction, and both are safe to call on a name that has already been converted — so you can translate defensively without having to track which form you are holding.

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.
}

View on GitHub →

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