Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/ironicmoka/moka-local-guard/archive/refs/heads/main.zipA single must-use plugin for WordPress developers who copy a live WooCommerce site to their computer.
A copy of the live database brings the live payment settings with it. Scheduled actions and test orders on the local copy can then reach real payment gateways, marketing services and analytics. Moka Local Guard is a safety net against that: it keeps gateways in test mode and blocks calls to production services, and it does nothing unless the site is marked as local.
It has no dependencies and no settings page.
What it does
On a site where wp_get_environment_type() returns local:
- Locks payment settings. Stripe, PayPal Payments and Satispay stay in test or sandbox mode, whatever the database says. Stripe's live keys read as empty. Changes to the locked keys from the dashboard are ignored.
- Blocks server calls made through the WordPress HTTP API to production services (see Presets), and logs them in
debug.logand in a dashboard notice. - Blocks tracking, from the server and in the browser: Google Analytics, Tag Manager and Ads, DoubleClick, the Facebook pixel, Bing, Clarity, Hotjar, LinkedIn and TikTok. Pages keep working, because only the destination of the requests changes. The
gtagandfbqstubs and the cookie banner behave as they do on the live site. - Lets you switch tracking back on to test cookie banners and real scripts: use the item in the admin bar or add
?moka_tracking=liveto a URL. It applies to that browser until it closes, shows a red label, and never unblocks the payment gateways.?moka_tracking=blockedturns it off.
What it does not do
It is a safety net, not a guarantee. Keep these limits in mind:
- It only runs in the
localenvironment. A database import does not change this, but copying the livewp-config.phpdoes: the guard then stops working without an error. Check thatWP_ENVIRONMENT_TYPEis stilllocalafter every copy. - Only the WordPress HTTP API is blocked on the server. A plugin that calls
curldirectly is not stopped. The Satispay SDK does this, and only the forced sandbox mode protects it. - Emails are not blocked. Use a mail catcher, or deactivate your SMTP plugin locally.
- Only array options can be locked, and only those listed in the presets or in your configuration.
- Scripts printed before
wp_head()are out of reach of the browser block. A tag written in the HTML may still be downloaded, but the measurement calls it makes are blocked.
Requirements
WordPress 5.7 or later and PHP 7.4 or later. Tested on WordPress 7.1.
Installation
Install it before importing the live database, so the guard is already active when the import finishes.
-
Make sure the site is local. In
wp-config.php:define( 'WP_ENVIRONMENT_TYPE', 'local' ); -
Copy
moka-local-guard.phptowp-content/mu-plugins/(create the folder if needed). -
If the site has payment gateways you want to test, add a configuration file.
Do not deploy it: it has no purpose outside a local site.
Configuration
Without a configuration file every preset is active, and the gateways that need sandbox credentials report them as missing in a dashboard notice.
Start from moka-local-guard.example.json. Keep the file outside the web root and outside any repository, and make it readable only by you (chmod 600), because it holds test credentials.
The guard looks for it here:
- the path in the
MOKA_LOCAL_GUARD_CONFIGconstant, defined inwp-config.php; - on a site made with Local,
moka-local-guard.jsonin the folder of the site, next toapp/.
| Key | Meaning | Default |
|---|---|---|
presets |
Presets to apply | all |
options |
Option keys to lock, by option name. This is where sandbox credentials go, and it works for any array option | none |
block_hosts |
More hosts to block on the server, with their subdomains | none |
tracking |
false leaves tracking alone |
true |
tracking_block |
More tracking rules, as host or host/path (for example a self-hosted Matomo) |
none |
Gateway credentials belong to the active environment, so sandbox mode on its own is not enough: PayPal and Satispay need their sandbox credentials in options. Copy them from the site's settings while it is still in test mode. Without them the gateway keeps the values in the database, production calls stay blocked, and payments will not work.
Presets
| Preset | Plugin | Locked | Blocked hosts |
|---|---|---|---|
stripe |
woocommerce-gateway-stripe |
test mode on, live keys empty | api.stripe.com, only for calls with a live key |
paypal |
woocommerce-paypal-payments |
sandbox on | api-m.paypal.com, api.paypal.com, api-3t.paypal.com, ipnpb.paypal.com |
satispay |
woo-satispay |
sandbox on | authservices.satispay.com |
facebook |
facebook-for-woocommerce |
graph.facebook.com |
|
4dem |
email-marketing-4dem |
api.4dem.it, mailchef.4dem.it |
Preset hosts match exactly, so sandbox hosts such as api-m.sandbox.paypal.com keep working.
Tests
wp eval-file tests/test-guard-plugin.php
The script runs from any WordPress site and does not activate the plugin. The browser block is tested with Node 22 or later, and skipped with a warning without it.
Credits
Designed, tested and maintained by Nicola Paroldo. The code, tests and documentation were written together with Claude (Anthropic) in Claude Code: decisions, review and every test on real sites are mine, much of the writing is Claude's.
License
GPL-2.0-or-later. See LICENSE.