Events sent elsewhere is refused from * the browser, in PHP and again in the runtime, whatever a rule says. The list * is empty by default: most sites want this plugin to send Purchase. * --------------------------------------------------------------------------- */ if (!defined('ABSPATH')) { exit; } define('STEPCOUNT_VERSION', '1.0.1'); define('STEPCOUNT_FILE', __FILE__); define('STEPCOUNT_DIR', plugin_dir_path(__FILE__)); define('STEPCOUNT_URL', plugin_dir_url(__FILE__)); // The plugin's website (docs and support). A site can override it in // wp-config.php; links are hidden when it is empty. if (!defined('STEPCOUNT_HOMEPAGE')) { define('STEPCOUNT_HOMEPAGE', 'https://step-count-main-website.vercel.app'); } require_once STEPCOUNT_DIR . 'includes/class-stepcount-config.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-store.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-page-cache.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-rest-guard.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-settings.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-capi.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-matcher.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-renderer.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-admin.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-log.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-health.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-setup.php'; require_once STEPCOUNT_DIR . 'includes/class-stepcount-diagnostics.php'; register_activation_hook(__FILE__, function () { StepCount_Settings::on_activate(); StepCount_Log::install(); StepCount_Setup::on_activate(); }); /** * Master switch. Define STEPCOUNT_ENABLED as false in wp-config.php to take * the whole thing off without deactivating the plugin or touching a file. */ function stepcount_enabled() { if (defined('STEPCOUNT_ENABLED') && !STEPCOUNT_ENABLED) { return false; } return (bool) apply_filters('stepcount_enabled', true); } /** * Is this host allowed to send real events? * * On any host not in the live-host list (see StepCount_Settings::live_hosts) * the plugin still runs and still logs to the debug overlay — it just never * dispatches. That is what makes staging testable without staging traffic * reaching a live dataset. */ function stepcount_is_live_host() { /** * Testing escape hatch. * * Its own constant, rather than adding the staging host to the live list: * that list may be shared with server-side code (a payment handler's * Purchase, say), and widening it would make every staging test payment * count as a real conversion. * * This switch moves the BROWSER events out of dry run and nothing else. * * define('STEPCOUNT_FORCE_LIVE', true); // in staging's wp-config.php * * Remove it when testing is done. It logs on every request precisely so it * cannot be left on quietly. */ if (defined('STEPCOUNT_FORCE_LIVE') && STEPCOUNT_FORCE_LIVE) { StepCount_Config::log('FORCE LIVE is on — browser events are being dispatched from ' . (string) wp_parse_url(home_url(), PHP_URL_HOST) . ' for real. This is a testing switch; turn it off.'); return true; } $allowed = StepCount_Settings::live_hosts(); if (empty($allowed)) { return true; // Not configured: behave as live rather than silently going dark. } $host = strtolower((string) wp_parse_url(home_url(), PHP_URL_HOST)); return in_array($host, $allowed, true); } add_action('plugins_loaded', function () { // Sites updated without re-activating (file copy, auto-update) still get // the log table. One autoloaded option read when nothing needs doing. StepCount_Log::maybe_install(); // The admin UI registers even when tracking is switched off — otherwise the // only way to turn it back on would be to edit wp-config, which is exactly // the situation the kill switch exists to avoid. if (is_admin()) { (new StepCount_Admin())->register(); (new StepCount_Setup())->register(); } if (!stepcount_enabled()) { return; } (new StepCount_Renderer())->register(); // The Conversions API mirror's endpoint. Registered in dry run too: it // logs what it would have sent, which is the point of a dry run. (new StepCount_Capi())->register(); (new StepCount_Health())->register(); });