benecaster_get_referral_code()
Returns the current customer’s referral code.
Access: Free (can be called from any context)
Since: feature/refer-a-friend-admin
Signature
benecaster_get_referral_code(): ?string
Return Value
A 32-character alphanumeric string — the customer’s unique referral code — or null when no code is available.
Returns null in these cases:
- The license server
feature/referral-programbatch has not yet shipped (the/validateresponse does not yet carry referral fields) - The site is an unlicensed (WordPress.org) install
- The plugin has not yet completed a validation run
This function reads from the locally cached benecaster_license_referral_code option — it does not make an HTTP call to the license server and is safe to call on every request. The value is refreshed during each daily validation run and cleared on plugin deactivation or an invalid validation response.
Usage
// Render the referral code in a custom widget
add_action( 'wp_dashboard_setup', function(): void {
wp_add_dashboard_widget(
'my_addon_referral_widget',
'Your Benecaster Referral Code',
function(): void {
$code = benecaster_get_referral_code();
if ( $code ) {
printf( '<p>Your code: <code>%s</code></p>', esc_html( $code ) );
} else {
echo '<p>Referral code not yet available.</p>';
}
}
);
} );
// Guard referral-specific add-on features
if ( benecaster_get_referral_code() !== null ) {
// Register referral-tracking integration
}
Notes
- Each customer has exactly one referral code — codes do not rotate.
- The referral link is
https://benecaster.com/ref/{code}. To get the full URL directly, usebenecaster_get_referral_link()— do not construct the URL from the code. - The referral code is only available after the license server
feature/referral-programbatch ships and begins including the field in/validateresponses. Existing sites will receive the field on their next daily validation run after the server batch ships.
Related
benecaster_get_referral_link()— returns the full referral URLbenecaster_get_referral_credit_cents()— returns the pending credit balance in cents- Refer a Friend — customer-facing explanation of the program