benecaster_get_addon_label()
Returns the human-readable display name for an add-on slug.
Access: Free (can be called from any context)
Since: feature/license-panel-info
Signature
benecaster_get_addon_label( string $slug ): string
Parameters
| Parameter | Type | Description |
|---|---|---|
$slug |
string |
An add-on slug, e.g. 'email-editor', 'analytics-dashboard' |
Return Value
The human-readable name for the add-on, sourced from the addons array in the cached benecaster_pricing_data transient.
If the transient is missing, stale, or does not contain the given slug, the function falls back to titlecasing the slug: hyphens and underscores are replaced with spaces and ucwords() is applied. For example, 'email-editor' → 'Email Editor' when the catalog is unavailable.
Usage
// List active add-ons with human-readable names
$active_addons = [
'email-editor',
'analytics-dashboard',
'guest-manager',
];
foreach ( $active_addons as $slug ) {
if ( benecaster_addon_is_active( $slug ) ) {
$label = benecaster_get_addon_label( $slug );
printf( '<li>%s</li>', esc_html( $label ) );
}
}
// Include add-on name in a license audit log
add_action( 'my_addon_activated', function( string $addon_slug ): void {
$label = benecaster_get_addon_label( $addon_slug );
error_log( sprintf(
'[Benecaster] Add-on activated: %s (%s) on %s',
$label,
$addon_slug,
home_url()
) );
} );
Notes
- This function always returns a non-empty string. When the slug is unrecognised and the catalog is unavailable, the return value is the titlecased slug rather than an empty string or
null. - The catalog is refreshed alongside license validation in the
benecaster_pricing_datatransient. On a cold install before the first validation run, the transient may be absent and the fallback will apply. - The slug passed must be a Benecaster add-on slug, not an arbitrary WordPress plugin slug. For the list of valid add-on slugs, see the add-ons marketplace.
Related
benecaster_addon_is_active()— checks whether a specific add-on is licensed and activebenecaster_get_plan_label()— same pattern for plan slugs