=== sitereal — headless companion ===
Contributors: sitereal
Tags: headless, astro, static site, deploy hook, rebuild
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Use this WordPress as the content source of a site built with sitereal: publishing rebuilds the site, and the sitereal app sees new posts on its own.

== Description ==

A headless site is built from WordPress, so a post published here changes nothing on the live site until the site is built again. This plugin closes that gap.

* **Rebuild on publish.** Publishing, updating, unpublishing, trashing or deleting content calls your host's deploy hook — Vercel, Netlify, Cloudflare Pages, Dokploy, Coolify, any URL. A burst of saves is one build.
* **Live in the app.** The sitereal app asks this site every half minute whether anything changed, and fetches the posts again only when it did — a new post appears on the canvas without a click.
* **Headless manners.** "View" in wp-admin opens the post on the built site, and visitors of the WordPress theme can be sent there too — all but a shop's checkout and customer account (SureCart, WooCommerce, FluentCart), which stay here.
* **A shop on the built site.** The built site shows the products and hands the cart to the shop's own checkout here: FluentCart takes a whole cart in one link through this plugin, and the status route says where each shop's checkout is and how it writes its prices.
* **The checkout in the site's design.** With Design of the shop pages set to the site's layout, the shop's checkout, cart, account and thank-you pages are drawn inside the Shop pages frame the built site carries — its header, footer, fonts and design — while the shop still takes the order and the payment.

The plugin does not change the REST API: sitereal reads the ordinary /wp/v2 routes, ACF, Meta Box and ACPT fields included. It adds two routes of its own: when content last changed, and the theme's preset colors, gradients and sizes, so a color picked for a block in the editor is the same color on the built site.

== Installation ==

1. Plugins → Add New → Upload Plugin, and choose sitereal.zip.
2. Activate it, then open sitereal in the admin menu.
3. Paste your host's deploy hook, and the address of the built site.

== Changelog ==

= 0.3.0 =
* Design of the shop pages is chosen in sitereal (the shop's settings there): this theme, or the site's design. The setting here follows it, or says Always this WordPress's theme. A site may give the checkout, the cart, the account or the thank-you page a frame of its own; every other shop page wears the shared one. With the site's design, the checkout, cart, account and thank-you pages of SureCart, WooCommerce and FluentCart are drawn inside the Shop pages frame the built site names in its /sitereal.json — the site's header and footer around the shop's own page, and the theme's styles left out of it (its color, size and spacing presets stay, for the shop's blocks). SureCart's customer dashboard keeps its own layout, which carries its menu.
* Nothing of the built site runs on a payment page: its scripts, iframes, event handlers and javascript: links are taken out when the frame is read. Its stylesheets and fonts are copied into wp-content/uploads/sitereal/frame, so the checkout depends neither on the built site answering nor on its host allowing fonts to be loaded from here.
* A frame that cannot be read keeps the last one in use (it is tried again after five minutes, or at once with Read again on the settings screen); with none ever read, the pages wear the theme. A new build of the site is picked up by itself.
* Site Health says which frame the shop's pages use, or why they fall back to the theme.
* A site in several languages: the shop's pages wear the frame in the language WordPress shows them in — WPML's or Polylang's current language, else the site's locale (TranslatePress sets it) — and the site's own language where the built site has no frame in that one.
* A product page the built site sends a visitor to for choosing options (?sitereal_stay=1) is drawn in the frame too; on a classic theme a WooCommerce product is drawn the way WooCommerce draws it.
* The theme's style rules are left out even where it prints them without a file (Bricks sets the page's root font size that way), and a shop's page template no longer styles the framed page through its body classes (SureCart's dashboard stylesheet did).

= 0.2.0 =
* FluentCart in headless mode: its checkout, cart, receipt, customer profile (and everything under it), order review, payment, login and registration pages stay on WordPress, as do pages holding its checkout, cart or account, and any request FluentCart answers itself. Its shop, product and category pages go to the built site.
* FluentCart takes a whole cart from the built site: /?fluent-cart=sitereal_cart&items=12:2,34:1&coupons=SAVE10 fills a new cart through FluentCart's own checks and opens its checkout. A line it cannot sell is said on the checkout and the rest stay; a subscription with other items is refused with FluentCart's own message.
* FluentCart rebuilds the site when a product, its prices or its variants change in its admin, deleting a product included. A sale does not, unless it sold something out.
* A shop's product page asked for with ?sitereal_stay=1 stays on WordPress in headless mode, for products the built site links to their page to be bought there (WooCommerce, SureCart and FluentCart products only).
* WooCommerce: an add to cart from the built site's form is answered with a redirect to the cart, so reloading the page does not add the item again.
* SureCart's saved items page (and any page holding a customer's saved items) stays on WordPress in headless mode, beside its checkout and customer dashboard.
* A SureCart sync that changes nothing no longer rebuilds because it ran in another language: SureCart writes its prices, billing intervals and dates out in the language of the request that syncs, so an admin's save in English and the next webhook in German looked like a change.
* The status route has a block for WooCommerce and for FluentCart beside SureCart's, and all three say the same things: the checkout, cart and account pages, the product and category bases, test or live, whether the store is closed (WooCommerce's Coming soon), whether the checkout takes a whole cart in one link, the currency, how prices are written and how tax is shown.

= 0.1.4 =
* Headless mode keeps WooCommerce's checkout links on WordPress. A link like /checkout-link/?products=12:2,34:1 (or /?checkout-link=1&products=…) was sent to the built site before WooCommerce could fill the cart; it now reaches the checkout with its items and coupon.
* WooCommerce's own requests from any address (wc-ajax, download links, cancelling or repeating an order) are never redirected either.

= 0.1.3 =
* Headless mode keeps a shop working: SureCart's checkout, order confirmation, thank-you pages, customer dashboard, Instant Checkout, upsell offers and email links stay on WordPress, as do WooCommerce's cart, checkout, My account and wc-api. Product, shop and collection pages still go to the built site.
* Only page views are redirected: a webhook or form POST is never turned into a GET on another host.
* Any other plugin's pages can stay on WordPress too: list their paths under Stays on WordPress, or use the sitereal_keep_on_wordpress filter. The settings screen names the shop pages it keeps by itself.
* A SureCart sale no longer rebuilds the site: a product sync that changes only stock counts is not a change. Selling out, a price or a name still is, and a product new in SureCart now is too.
* WooCommerce: a price, a name or a sell-out changed through WooCommerce itself (its REST API, a CSV import, an order's stock update) now rebuilds; a sale that only moves the stock count still does not.
* A published post deleted outright, without the trash (WP-CLI, the REST API, SureCart removing a product), starts a build.
* The status route says where SureCart's checkout and dashboard are, its product and collection bases, and whether the checkout is in test mode.
* The theme's preset colors, gradients and font sizes at /wp-json/sitereal/v1/styles: a color or size picked for a block in the editor (has-vivid-red-color and the like) is the same color or size on the built site, the theme's own presets included.
* DDEV's and Lando's addresses (.ddev.site, .lndo.site) count as this computer, like LocalWP's: the settings say to publish from sitereal, and the app is told so.

= 0.1.2 =
* Headless mode: one switch discourages search engines and sends visitors of the theme to the built site.
* sitereal has its own entry in the admin menu.
* Where each post is on the built site is read from that site's /sitereal.json, which sitereal writes with every build — no setting here, no login needed.

= 0.1.1 =
* Knows when WordPress runs on this computer (LocalWP, .local, a private address): the settings say to leave the deploy hook empty and publish from sitereal, and the app is told so.
* Updates from sitereal.app inside wp-admin, like any other plugin.

= 0.1.0 =
* First release: rebuild on publish, the status route the app reads, View links and the front-end redirect.
