benecaster_get_referral_link()
Returns the full referral URL for the current customer.
Access: Free (can be called from any context)
Since: feature/refer-a-friend-admin
Signature
benecaster_get_referral_link(): ?string
Return Value
The full referral URL string (e.g. https://benecaster.com/ref/a1b2c3d4...), or null when no referral link is available.
Returns null in the same circumstances as benecaster_get_referral_code(): the license server feature/referral-program batch has not yet shipped, the site is unlicensed, or no validation run has completed. When benecaster_get_referral_code() returns null, this function also returns null.
This function reads from the locally cached benecaster_license_referral_link option — no HTTP call. Refreshed during each daily validation run; cleared on deactivation or invalid validation.
Usage
// Add a referral link to a custom email notification
add_action( 'benecaster_subscriber_activated', function( int $user_id, int $show_id ): void {
$link = benecaster_get_referral_link();
if ( ! $link ) {
return;
}
$user = get_userdata( $user_id );
wp_mail(
get_option( 'admin_email' ),
'New subscriber — share your referral link',
sprintf(
'You have a new subscriber on %s. ' .
'Know another podcaster? Share your referral link: %s',
home_url(),
$link
)
);
}, 10, 2 );
// Display referral link in a custom shortcode
add_shortcode( 'my_referral_link', function(): string {
$link = benecaster_get_referral_link();
if ( ! $link ) {
return '';
}
return '<a href="' . esc_url( $link ) . '">' . esc_html( $link ) . '</a>';
} );
Notes
- Use this function rather than constructing the URL from
benecaster_get_referral_code()— the URL format is controlled by the license server and may change. - The URL when visited by a new visitor sets a 30-day attribution cookie and redirects directly to the SureCart checkout page with the referrer’s discount code pre-applied.
Related
benecaster_get_referral_code()— returns the raw referral codebenecaster_get_referral_credit_cents()— returns the pending credit balance in cents- Refer a Friend — customer-facing explanation of the program