Getting Started

What the Safety Checks Test

Published

The safety checks in the Cache Upgrader Kit for WooCommerce prove that a page is safe to serve from your page cache to every kind of shopper. Your AI agent runs them, reads the result and fixes what fails. This guide covers three groups of checks that look at what a shopper does on the page, where the rest compare what the page contains: payment buttons, private pages, and the speed check’s Basket and Checkout timings.

Available since 1.8.0.

Payment and express-checkout buttons

Express-checkout buttons (PayPal, Stripe, Klarna, Apple Pay, Google Pay, Amazon Pay and others) sit on product pages, shop pages and mini-baskets. Those are the pages the cache serves to everybody, so the button’s script arrives the same for every shopper, and its first request to your store carries a security token that has to belong to the shopper making it.

The checkout page and the basket page are different. They are private pages, never cached, and their buttons behave exactly as the payment plugin built them.

What the check does

The safety run loads each page it checks in a real browser as a new visitor. A product page is also loaded as a shopper with one item in the basket, and as a logged-in customer with one item in the basket. For each of those visitors, your store records every request the page’s scripts make back to it: the address, the answer, which security-token fields the request carried and whether they were empty, and which plugin owns the code that answered.

The row is called Payment buttons: the first request is accepted, and there is one for each visitor.

ResultWhat it means
PassA payment plugin made requests and none was refused over its token, or no payment script loads on that page.
FailA payment plugin’s request was refused over its security token. The run is not green, even when a later attempt was accepted: the button appears late, or not at all.
WarningNo token was refused, but a payment request failed for another reason (an account that is not connected on a staging site, for example), or a payment script loaded and made no request. The button could not be confirmed working there.
UnresolvedThe visitor could not be set up. The usual cause is that the test customer does not exist.

The check reads requests. It carries no list of payment providers, so it covers whichever one your store runs, and a provider added later is covered without an update.

No payment is ever made and no payment button is ever clicked.

What a failure tells your agent

A failed row names everything a fix needs:

  • the plugin, and the request that was refused, with the answer your store gave;
  • the token field, and whether it was sent empty or sent and refused;
  • the name WordPress gives that token (its nonce action), when WordPress refused it;
  • whether the request went before or after the shopper’s own data arrived on the page;
  • how many attempts were made and whether a later one was accepted;
  • the recipes that handle that plugin, and whether each is on, off or skipped, with the reason for a skip;
  • where the page carries that plugin’s tokens, and the script they were printed for.

Two different faults produce a refused request, and the row tells them apart:

  • The token belongs to somebody else. The cached page still carries the token of whoever’s visit filled the cache. The fix is a recipe that leaves the token empty in the cached page and fetches each shopper’s own.
  • The token arrives too late. The recipe fetches each shopper’s own token, but the payment script starts with the page and reads the empty value first. The row says the token “was sent empty”, “before the per-visitor data was returned”. The fix is to hold the script until the token has arrived.
Common mistake

Fetching a fresh token for each shopper is half a fix when the payment script starts with the page. The script reads the token before it arrives, sends an empty one, and is refused. The recipe has to do both: fetch the shopper’s token, and hold the script until it is there.

How your agent builds a recipe for your payment provider

Your agent has two tools for this, on top of reading the payment plugin’s own code on your site.

The token map. The ssapco/list-page-tokens ability takes one page address and lists every security token in the cached copy of that page:

  • where it is, for example wc_ppcp_sdk_v6.ajax.client_token.nonce, or a hidden form field;
  • its nonce action;
  • the script it was printed for, with that script’s file, its plugin and how it loads;
  • whether a recipe fetches it per shopper;
  • whether its script is held until it arrives.

Token values are never included.

The hold. A recipe calls SSAPCO_Runtime_Data::hold_script() with the script’s handle and the token it needs. On cached pages the script is added only once that token is in place. Scripts that depend on it wait behind it, in order. If the token never arrives, the script does not start and the browser console says so. Nothing falls back to another shopper’s token.

A recipe for an express provider is those two calls, with the values the token map gives:

SSAPCO_Runtime_Data::register_object('my-provider-tokens', 'providerConfig', array(
    'ajax.client_token.nonce' => function () { return wp_create_nonce('provider-client-token'); },
));
SSAPCO_Runtime_Data::hold_script('provider-sdk-boot', 'providerConfig', 'ajax.client_token.nonce', 'my-provider-tokens');

The library recipe for WooCommerce PayPal Payments is built this way and is the worked example your agent reads.

The test customer

The logged-in payment check and the private-page checks log in as one account only: a customer called cache-upgrader-test. A real customer’s account is never used in a browser, because a payment script could start a payment session or save a payment method for that person.

Your agent asks you before creating the account, and asks which email address it should use. The account has the Customer role, no orders, a billing name and email, and a random password that is not shown to anyone. You can delete it at any time; the checks that need it then report that it is missing.

When the account does not exist:

  • the logged-in payment row is unresolved, so the run is incomplete, when a payment plugin is active;
  • the private-page requests are reported as not checked.
Note

In wp-admin, run the safety checks in Chrome or Edge. Those browsers give the check’s page its own cookies, which the basket and logged-in payment checks need. In Firefox and Safari those two rows report that they could not run. Your agent’s own runner is not affected.

Private pages

A private page always keeps the visitor’s identity. A logged-in customer is never given the shared copy of it, and it is never stored in the cache. The basket, the checkout and My account are private on every store.

The list, and where each entry comes from

The list of private paths is shown in three places: the Cache Upgrader tab of Super Speedy → Ajax, the safety report, and private_paths in the ssapco/get-status ability your agent reads. Each path is shown with its source:

SourceWhat it covers
WooCommerce page settingsThe basket, checkout and My account pages, wherever you have put them.
The owner’s listPaths you add under “Pages that always keep the visitor’s identity”: a wishlist, a returns form, a members’ area.
A recipe or custom codePaths a recipe adds through the ssap_guest_render_excluded_paths filter.
WordPressThe login page and the REST API.

Your agent reads the list to you and asks what is missing.

Best practice

Add every private path in two places: the Cache Upgrader list, and your page cache’s own exclusions. The first stops WordPress building a shared copy of the page. The second stops the cache storing or serving one.

The three private-page rows

Private pages keep the customer’s identity and stay out of the cache. Each private page is requested twice as the logged-in test customer, on its plain address with no extra parameters, exactly as a customer’s browser asks for it. The row fails when:

  • the page was given to the customer as a guest;
  • the second request was served from the page cache;
  • the page’s headers do not tell caches to keep it out.

A fail on the second request means the page cache’s own exclusions are missing that path.

The safety checks leave private pages as the plugins print them. The same page is requested with and without the safety check’s test state, and must carry the same security tokens both times.

Pages that show a customer something personal are private. Every other published page is compared for a guest and for a customer. Differences that appear on every page of the store, such as an account link in the header, are set aside. A page with a difference of its own is named in a warning, with where the difference starts:

A logged-in customer sees something on these pages that a guest does not, and they are not private: /returns-form/

It is a warning because the decision is yours. If the page is personal, add its path to the list and to your page cache’s exclusions. If the guest version is fine for everyone, leave it.

Basket and Checkout in the speed check

The kit’s speed check times your store’s pages for a guest, a shopper with one item in the basket, and a logged-in customer, and records whether each page came from the cache.

The shopper with a basket and the logged-in customer are also timed on the Basket and Checkout pages. A guest’s basket is empty, so the table shows “empty basket” in those two columns.

ShopperHomeShopCategoryProductMy accountBasketCheckout
Browsing (guest)timedtimedtimedtimedtimedempty basketempty basket
One item in the baskettimedtimedtimedtimedtimedtimedtimed
Logged-in customertimedtimedtimedtimedtimedtimedtimed

The Basket and Checkout pages are never cached, so their cache status reads bypass or miss in every phase, and their time is what the shopper waits for WordPress. That time is the one to watch after switching caching on: with basket and logged-in pages served from the cache, fewer PHP workers are busy, and the pages that still need WordPress get an answer sooner at busy times.

Common mistake

A cache hit on the Basket or Checkout page is a fault. The speed check stops, names the page and tells your agent to tell you. Exclude that page from your page cache before doing anything else.

Further reading

the setup, the safety loop and going live
get the kit running on your store
how staff stay on fresh pages

Written for Cache Upgrader for WooCommerce 1.8.0.

Fixing this on a real store?

Cache Upgrader Kit for WooCommerce does it for you.

Comments