How Gatemi Private Store Works

Three rules shape the plugin.

Rule 1: removed, not styled away

A product id is a guessable number. A direct address, a bookmark, a search engine's memory or a REST call can all reach a product without passing through a shop page. So the same decision is enforced in four places:

  1. The shop queries. With Hide on, protected products are taken out of shop, category, tag and search results. Only the ids the rules name are excluded — the plugin never scans the catalogue on a page view.
  2. Visibility. WooCommerce's own "is this product visible?" answer is no for a protected product (with Hide on).
  3. Purchasable. A protected product is not purchasable. This one answer is what covers the classic cart, the Cart and Checkout blocks and the Store API without the plugin needing to know about each.
  4. Add to cart. An attempt to add a protected product is refused with the reason. A protected product already in a cart — from before the rule, or before somebody signed out — is removed at the cart check, with a notice.

On top of that, the product's own page, a protected category's page and (for a whole-shop rule) the shop pages are refused: the visitor sees the "This area is private" page instead.

With Hide on, protected categories also leave category lists and menus, so a menu never links somewhere a visitor will be refused.

Rule 2: every rule must be satisfied — Full edition

A product can be covered by more than one rule: a whole-shop "signed in" rule and a "trade" category rule, for instance. The visitor must satisfy every rule that covers the product.

Why not the first matching rule? Because then a broad rule added at the top of the list would quietly unlock everything the narrower rules below were protecting. With "every rule", adding a rule can only ever protect more.

When a visitor is refused, the page explains the first rule they do not satisfy, because that is the one whose message and password box they need.

Who satisfies what

Who may see it Satisfied when
Anyone signed in The visitor is signed in
These roles only Any of the visitor's roles is in the list (guest = not signed in). Every role a user holds is read, not just the first
Anyone with the password The visitor has entered that rule's password and it is still remembered

Anyone who can edit products (edit_products) satisfies every rule, so you can check your own shop without knowing the password you set for customers.

What a rule covers

  • The whole shop — every product.
  • These categories — products in those categories or any of their sub-categories.
  • These products — those products and, for a variable product, its variations.

Rule 3: a password unlocks a rule — Full edition

  • The password is stored hashed with WordPress' own password hashing. It is never stored in the clear: a shop's trade password is often one customers use elsewhere.
  • A correct password puts a token in a cookie, gmpv_unlocked. The token is a signature over the rule's id and the stored password hash, made with your site's secret keys. It holds no secret and cannot be forged from a rule's name.
  • Changing a rule's password closes every unlock already handed out, because the old tokens no longer match.
  • The cookie lasts as long as A password stays unlocked for says (one day by default). It holds at most 20 unlocks.
  • After a correct password, the visitor is sent back to the page they were on.

The refused page

The plugin replaces the page's template with its own templates/protected.php, inside your theme's header and footer. It shows:

  • the heading "This area is private";
  • the rule's own sentence, or one matching the reason;
  • a Sign in button (to your sign-in page, returning to this page), or a password box for a password rule.

A theme can replace it by putting its own copy at yourtheme/gatemi-private-store/protected.php.

Full edition: with Send them to sign in, a visitor refused for a login or role rule is redirected instead; with Show "not found", a visitor refused by a login or role rule gets a 404 instead. A password page always shows its box, whichever mode is chosen: signing in cannot lift a password, and a 404 page has nowhere to type one.

Why page caches are switched off

While protection is on, storefront pages are sent with no-cache headers and DONOTCACHEPAGE is defined. A signed-in trade customer and an anonymous visitor see different shops. A page cache that served one the other's page would expose the protected products — or hide them from the people who should see them.

The free edition, step by step

  1. Only signed-in customers may see the shop is on.
  2. Its one rule covers the whole shop or the chosen categories.
  3. A visitor who is not signed in is refused those products, everywhere listed above. Anyone signed in sees everything.
  4. Only the rule with the id private-store is read. Other rules the full edition wrote stay stored but are not evaluated.
Shopping Cart
Scroll to Top