benecaster_get_addon_manager_tokens()
benecaster_get_addon_manager_tokens(): array
Returns the site tokens the Benecaster Add-on Manager authenticates with when it asks the license server about installs and updates. It exists for the Add-on Manager only and is not a general-purpose way to read a license.
Shows in reconnect-required state are skipped, two shows on one license give one entry, and a token stored with no license id is its own entry with license_id: null. Benecaster does not merge entitlements across licenses or pick a token for a given add-on: ask with every entry and merge the answers.
Return Value
Type:
list<array{license_id: int|null, token: string}>
One entry per distinct license on this site: [ 'license_id' => int|null, 'token' => string ]. An empty array when nothing is connected, or when the caller is not allowed to see tokens.
Example
// In the Benecaster Add-on Manager, before asking the license server about updates.
if ( ! function_exists( 'benecaster_get_addon_manager_tokens' ) ) {
return; // Benecaster is not active.
}
foreach ( benecaster_get_addon_manager_tokens() as $entry ) {
// Ask with $entry['token'] (as Authorization: Bearer, to the updates host only),
// then merge the answers across entries.
}
Notes
A site token is a credential. The function answers only for a user who can
manage_options, under WP-Cron, or under WP-CLI, and returns an empty array to anyone else, so
update checks and auto-updates work from cron. Send a token only as Authorization: Bearer to
the updates host; never log it, render it, or pass it to a hook.
Treat each license_id: null entry as a separate license and never key on the null.
Check function_exists() first. When Benecaster is deactivated the function does not
exist, and the Add-on Manager has nothing to ask with.
Benecaster detects the Add-on Manager by defined( 'BENECASTER_MANAGER_VERSION' ) alone.
Need this built rather than just documented? See our services →