Skip to main content

Keep staging test data out of your production CRM and email lists

Free Intermediate Since v1.0.0

When you test on a staging site, Benecaster fires the same hooks as on production — which means any integration you’ve built (CRM sync, Slack notification, mailing list tag) will also run, pushing test data into your live systems. A single guard at the top of each hook callback prevents this.

Benecaster detects staging automatically on known hosting domains. If your staging URL isn’t automatically recognized, add define('BENECASTER_STAGING', true) to wp-config.php to force it. Either way, the check is a one-liner that returns early when staging is active. The same pattern applies anywhere you make an outbound call — subscriber events, episode publications, token generation — any hook that touches an external service.

See Setting Up a Staging Site for how Benecaster recognizes staging environments and how to configure the constant on domains it doesn’t detect automatically.

Code

<?php
add_action(
    'benecaster_subscription_activated',
    function ( int $user_id, int $show_id, string $tier_slug, string $source ): void {
        $staging = benecaster()->container()->make( \Benecaster\Staging\StagingManager::class );
        if ( $staging->is_staging() ) {
            return; // Don't push test subscribers to the production CRM.
        }
        my_crm_tag_contact( get_userdata( $user_id )->user_email, [
            'benecaster_subscriber' => true,
            'tier'                  => $tier_slug,
            'source'                => $source,
        ] );
    },
    10, 4
);