For developers
Constants, filters, storage and hooks in the ChangeTrace WordPress plugin.
Reference for the plugin's developer surface. There is no public HTTP API — every endpoint is either a dashboard session or a site token issued to the plugin.
Requires: WordPress 6.2+, PHP 8.1+. Neither is checked at runtime, so an under-spec site fatals rather than degrading.
Constants
Define in wp-config.php before WordPress loads:
define( 'CHANGETRACE_API_BASE_URL', 'https://api.change-trace.com' );
define( 'CHANGETRACE_APP_URL', 'https://app.change-trace.com' );
define( 'CHANGETRACE_PRIVACY_URL', 'https://change-trace.com/privacy-policy' );
define( 'CHANGETRACE_TERMS_URL', 'https://change-trace.com/terms-of-service' );The first two are what you change to point a staging site at a different environment.
Filters
// Same four values, at runtime.
add_filter( 'changetrace_api_base_url', fn( $url ) => 'https://api.staging.example.com' );
add_filter( 'changetrace_app_url', fn( $url ) => 'https://app.staging.example.com' );
add_filter( 'changetrace_privacy_url', fn( $url ) => $url );
add_filter( 'changetrace_terms_url', fn( $url ) => $url );
// JavaScript error sampling. Default 0.25. Use 1.0 to capture everything while debugging —
// it is a real bandwidth cost on a busy site, so put it back afterwards.
add_filter( 'changetrace_js_error_sample_rate', fn( $rate ) => 1.0 );Scheduled jobs
| Hook | Schedule | Does |
|---|---|---|
changetrace_heartbeat | Hourly | Posts a heartbeat |
changetrace_flush_queue | Every 5 minutes (custom schedule changetrace_flush_interval) | Sends up to 50 queued events |
Both re-schedule themselves on init when a token is present, so a lost cron entry heals itself.
Deactivation clears both.
Change detection
Change_Detector diffs the current state against changetrace_state_baseline on
upgrader_process_complete, switch_theme, activated_plugin, update_option_active_plugins
and deleted_plugin, plus a 5-minute-throttled admin_init reconcile that catches WP-CLI and SFTP
changes.
Two distinctions the diff makes that are easy to miss:
- A plugin appearing on disk inactive emits
plugin_installed; appearing active emitsplugin_activated. They are separate events. - The active theme changing stylesheet emits
theme_changed(withtemplatenaming the parent when the new theme is a child); the same stylesheet moving version emitstheme_updated. When the active theme is a child, its parent moving version emits a secondtheme_updatedwhosestylesheetis the parent's directory, plusparent_ofnaming the child.
Storage
No custom tables. Twelve options, none autoloaded:
| Option | Holds |
|---|---|
changetrace_site_token | The site token |
changetrace_connected_host | Domain pin for clone detection |
changetrace_consent | Consent record: agreed, version, time, user, site URL |
changetrace_connect_pending | In-flight handshake state |
changetrace_connect_last_error | Last connect failure |
changetrace_last_heartbeat | Time, ok, HTTP code |
changetrace_installed_at | Activation timestamp |
changetrace_event_queue | Pending events |
changetrace_flush_backoff | Retry state |
changetrace_remote_config | Cached configuration, 1-hour TTL |
changetrace_snapshot_sent_at | Snapshot timestamp |
changetrace_state_baseline | Last-seen plugins, theme, WP and PHP versions |
Plus two transients (changetrace_activation_redirect, changetrace_reconcile_lock) and one
user meta key for notice dismissal. Uninstall removes all of it.
Queue behaviour
- Bounded FIFO, 500 events; when full the oldest are dropped.
- Flush every 5 minutes, 50 per batch.
- Events are removed only after the API returns 2xx.
- On failure: exponential backoff from 60s, doubling, capped at 3600s, 8 attempts.
- No-op when disconnected or in safe mode.
Event types
The underscore forms are the real contract.
Changes: plugin_installed, plugin_activated, plugin_deactivated, plugin_updated,
plugin_removed, theme_changed, theme_updated, core_updated, php_version_changed,
option_changed
Errors: php_error, php_fatal, js_error, http_5xx, http_timeout, rest_5xx
WooCommerce: order_created, order_failed, payment_failed, checkout_started,
checkout_failed, refund
checkout_started and checkout_failed carry checkout_type (classic | block). On the block
checkout, checkout_started fires when the Checkout block renders with a non-empty cart, and
checkout_failed when a Store API checkout (POST /wc/store/v1/checkout) fails with a 4xx or 5xx —
it then carries the Store API error_code (never the message, which can echo customer input).
A refused payment (woocommerce_rest_payment_error) is reported as payment_failed instead, with
the order's fields, unless the gateway already marked the order failed. Only requests carrying a
valid Store API nonce count — a real shopper's browser — so endpoint spam, nonce (401/403),
rate-limit (429) and empty-cart rejections are not recorded.
EDD: edd_order_created, edd_order_failed, edd_checkout_started, edd_checkout_failed,
edd_payment_failed, edd_refund
edd_checkout_started fires once when the purchase form renders (shortcode, Checkout block or
Elementor) and carries checkout_type (classic | block). edd_checkout_failed fires when EDD
rejects a submission, carrying the first EDD error_code (never the message) and payment_method.
Only submissions with a valid edd-process-checkout nonce (or EDD's cache-safe token) count; one
carrying an empty-cart, nonce or captcha error never does, and each visitor session reports at most
three. Stripe card declines happen in the browser and never mark an order failed, so the plugin
reports them as edd_payment_failed (payment_method: stripe, order_id: 0, error_code = the
Stripe decline code) when EDD's Stripe script records a card_error — card-form typos
(validation_error) never count — and only after EDD has created a Stripe payment for that
visitor's checkout, at most three per payment.
Every event is wrapped in an envelope carrying a client-generated event_id (UUID v4), the site
URL, type, ISO-8601 UTC timestamp, source, schema version and severity. Ingestion deduplicates on
event_id, so re-sending a batch is safe.
These are the canonical names, declared on each side of the contract and compared by a test:
- Plugin side —
includes/Support/Event_Types.php. One class constant per type; collectors reference the constants rather than bare strings. - Backend side —
packages/event-schema, which every API module derives its lists from.
The test asserts the two sets are equal, so neither side can gain or lose a type alone, and separately rejects any collector passing a bare string literal where an event type belongs. That second check is what keeps the declaration honest — without it a new type could be introduced at a call site and never reach the declaration.
Why a declaration rather than scanning the code
This used to infer the list by pattern-matching emission call sites, which could not see a type
chosen before the call. The plugin does that three times — plugin_installed,
edd_payment_failed and edd_order_failed are each picked by a ternary — so three of its types
were invisible to the guard, and refund would have escaped a name-shape heuristic too. Comparing
declarations removes the problem rather than widening the pattern.
Names that no longer exist
http_error and http_failure were never emitted by any collector and have been removed from the
backend entirely — use http_5xx and http_timeout. Likewise woocommerce_order_created,
woocommerce_product_updated, woocommerce_settings_changed, uptime_check and health_check
were never real event types.
Declared but not implemented
The remote configuration lists a user_role_changes module, but no collector emits it — do not
build on it. heartbeat_interval_seconds is present in the config and read, but nothing consumes
it; the heartbeat is WordPress's hourly schedule.
Watched options
option_changed fires only for an explicit allowlist, never for every option write:
| Matched by | Options |
|---|---|
| Exact name | permalink_structure, siteurl, home, active_plugins, template, stylesheet, blog_public, auto_update_core_major |
| Pattern | woocommerce_<gateway-id>_settings |
// Add your own. Exact names only — the allowlist itself is not configurable away.
add_filter( 'changetrace_watched_options', fn( $names ) => [ ...$names, 'my_plugin_mode' ] );The event carries the option name and a summary of the old and new values —
{ type, size|length, digest } — never the value. Several watched options hold live credentials.
Identical writes (WordPress fires updated_option even when nothing changed) are suppressed, as
are repeat writes of the same option within one request.
REST route
One, and it is for the plugin's own bundled script:
POST /wp-json/changetrace/v1/client-errorRequires a valid X-WP-Nonce. Always returns 204, including on error — it never 500s, and it
drops silently when the site is not connected. Bodies over 16 KB are replaced with a stub.
Outbound endpoints
| Endpoint | Purpose |
|---|---|
POST /api/v1/connect/exchange | Swap a one-time code for a token (the only unauthenticated call) |
GET /api/v1/sites/me/status | Verify a token |
GET /api/v1/sites/me/config | Fetch remote configuration |
POST /api/v1/sites/me/snapshot | Send the baseline snapshot |
POST /api/v1/sites/heartbeat | Hourly heartbeat |
POST /api/v1/sites/events/batch | Send queued events |
All carry Authorization: Bearer site_tok_… except the exchange, plus an
X-ChangeTrace-Site-Url header the API validates — a mismatch is a 409, which is what enforces
safe mode server-side.
Debugging
There is no debug toggle and no log file. Connect failures are written with error_log() only
when WP_DEBUG is true. The status table and the Send test heartbeat button are the plugin's
entire diagnostic surface.
Sanitization
Applied on your server, before sending. Recursive key-based redaction across ~40 sensitive key substrings, regex redaction of email addresses and 12+ digit runs inside strings, query string and fragment stripped from URLs, absolute paths rewritten relative to the WordPress install, 8 KB payload cap and 2,048-character string cap with truncation markers.

