Skip to main content

benecaster_get_live_referral_balance()

Utilities Free
benecaster_get_live_referral_balance(): ?int

The podcaster’s referral credit balance, fetched live from the licence server. It is the figure the Refer a Friend page shows, and the one to show anywhere else.

On null, show no figure at all. Link to the account page (https://benecaster.com/my-account/#benecaster-account-referral) instead. Never fall back to benecaster_get_referral_credit_cents(): a stale, or fail-open, zero shown as the balance is exactly what this function exists to prevent.

The balance is per customer, not per site. Someone running two sites sees the same figure on both, so present it as credit on the podcaster’s account, not on this site.

Admin use only. It asks the licence server at most once every five minutes per site and reuses the answer in between, so the figure can be up to five minutes old. On a front-end request it never calls out: it returns a reused answer or null. Call it from wp-admin screens, dashboard widgets and cron, not from theme templates.

A successful answer also refreshes the cached link, code, sign-up count and email preference that the other benecaster_get_referral_* functions read.

Return Value

Type: ?int

The customer's live referral credit in whole cents, or null when there is no live answer to give. That covers a licence server that is unreachable, refusing (a lapsed licence, a rate limit) or unable to read the figure; no connected show; and a front-end request with nothing to reuse.

Example

$balance = benecaster_get_live_referral_balance();

if ( null === $balance ) {
    // No live answer: show no figure, and link to the account page instead.
    printf(
        '<a href="%s">%s</a>',
        esc_url( \Benecaster\License\LicenseManager::REFERRAL_DASHBOARD_URL ),
        esc_html__( 'See your current referral credit on benecaster.com', 'my-addon' )
    );
} elseif ( $balance > 0 ) {
    printf(
        esc_html__( '%s in referral credit on your Benecaster account.', 'my-addon' ),
        esc_html( '$' . number_format( $balance / 100, 2 ) )
    );
}

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