benecaster_payment_test_mode_active()
benecaster_payment_test_mode_active( ?int $show_id = null ): bool
Whether payments in the requested scope are running against test credentials rather than live ones. Safe to call from theme templates and add-ons regardless of plugin boot state — it returns false if the plugin container is not yet available, so it never fatals in a template.
The two call forms are not the same question at two scopes. With a show it answers about Stripe; without one it answers about every registered payment gateway. See the notes.
Use it to show a “payments are not real” notice while rehearsing a signup flow.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
show_id |
int|null |
null |
No | Show to ask about. Omitting it does not ask the same question about a wider scope — it asks a different question of a different subsystem. See the notes. |
Return Value
Type:
bool
true when payments in the requested scope are not real. With a show ID, that is the mode that show will actually transact in. With no argument, it is true when any gateway on the install is in test mode.
Example
// In a show-scoped template, pass the show.
if ( benecaster_payment_test_mode_active( get_the_ID() ) ) {
echo '<p class="notice">Payments for this show are in test mode — no card will be charged.</p>';
}
// With no show in scope, the answer is about the install default.
if ( benecaster_payment_test_mode_active() ) {
echo '<p class="notice">This site has payments in test mode.</p>';
}
Notes
The two call forms read different subsystems, and the docs previously implied they read one. This is not an optional narrowing parameter:
- benecaster_payment_test_mode_active( $show_id ) resolves through StripeClient::is_test_mode( $show_id ) — the show's own mode when it has a complete keyset for one, the install default otherwise. It sees Stripe and nothing else.
- benecaster_payment_test_mode_active() resolves through PaymentTestModeManager::any_gateway_in_test_mode(), which walks the gateway registry and returns true if any registered gateway reports test mode.
Two consequences, neither guessable from the signature. A third-party gateway in test mode makes the bare call return true even when Stripe's install default is live — so the bare call is not "the Stripe install default", and reading it as such is wrong on any install with a gateway add-on. Conversely, adding a show ID can flip the answer from true to false for a reason that has nothing to do with that show, because the show-scoped path never consults the registry.
If the Stripe install default is genuinely the question, neither form answers it — there is no function-level equivalent of StripeClient::site_is_test_mode(). Reach for the class.
$show_id is optional but rarely omittable on a multi-show install. Test mode is resolved per show, so a site can sit in live while one show is in test, and the reverse.
Pass a show whenever the caller has one. A template that tells a subscriber of a live show that "payments are not real" — because some other show on the site is rehearsing — is worse than saying nothing at all: it invites them to believe a real charge was a test.
Calling it bare is legitimate where there is genuinely no show in view. Benecaster's own account dashboard does exactly that, because it spans every show a subscriber belongs to and has no single show to ask about.
A show only has a mode of its own when it carries a complete Stripe keyset for that mode. A show on the site account always answers with the install default, so passing its ID is harmless rather than wrong.
Need this built rather than just documented? See our services →