FlexPlat logoFlx Modernize

Flx Modernize plugin

Version 1.14.0 · WordPress 6.0+ (tested to 7.1) · PHP 7.4+ · GPL-2.0-or-later

Flx Modernize is the WordPress side of Flx. For each eligible request it builds the page data, sends it to your Flx Render service in a signed request, and sends the visitor the HTML that comes back. If anything goes wrong, it steps aside and WordPress renders the page as usual.

How a request is handled

  1. Eligibility. The request must be an anonymous visitor's GET or HEAD request for an HTML page (not a feed, embed, robots.txt, favicon or trackback). Logged-in users always get normal WordPress (one opt-in exception for store customers: see WooCommerce stores), and so do visitors who have commented (WordPress's comment cookies) and reply or "awaiting moderation" links (replytocom, unapproved), so a commenter sees their own pending comment.

  2. WooCommerce (since 1.7.0). With WooCommerce active, these get normal WordPress:

    • the store: the shop, products, product categories and tags, cart, checkout, My account and its endpoints, product search, and WooCommerce's AJAX and API requests;
    • visitors with a WooCommerce cart or session cookie, on every page;
    • the whole site while WooCommerce's "Coming soon" mode is on.

    The site's pages and posts keep using Flx. Without WooCommerce nothing changes. A store on the Storefront or Astra theme can opt in to more: see WooCommerce stores.

  3. Filter. flx_modernize_should_render can turn Flx off for the request. It can never turn it on for a request that failed steps 1–2.

  4. Route. The plugin recognises the blog home page, category and tag archives, single posts, pages, search results and the 404 page. Anything else stays WordPress.

  5. Content checks. Previews, drafts, private and scheduled content and any post with a password stay WordPress. A password-protected post is never sent, even to a visitor who has entered the password.

  6. Page data. The payload is built as the anonymous visitor (user 0), so content filters and dynamic blocks never see a user. See Flx Render for the fields.

  7. Render. The payload goes to the Render service (5-second timeout). On success the HTML is sent with Cache-Control: private, no-store, or a public header if you turn on edge caching; a 404 keeps its 404 status.

  8. Fallback. On any failure (timeout, error, invalid response) the visitor gets the normal WordPress page, sent with Cache-Control: no-store. Once page data was built, that page is fetched fresh from the site itself as the same visitor, so nothing the plugin ran while building can change it (1.10.0, ADR-0022); if the site cannot reach its own address, WordPress renders it in the same request, as before. FLX_MODERNIZE_LOOPBACK_FALLBACK set to false turns the fresh fetch off.

    • A page type the service doesn't offer (since 1.7.0): if the Render service answers HTTP 404 (it has no route for that page type), the plugin remembers it for an hour. During that hour, that type is served by WordPress (still no-store) without calling the service.
    • Clearing the memory: changing the Render URL or signing key clears it at once.

Both rendered and fallback responses also define DONOTCACHEPAGE, so page-cache plugins don't store them. If output has already started before the plugin runs, it stays out of the way, because the cache headers could no longer be sent.

Install and configure

Everything is done in wp-admin (since 1.12.0); no file needs editing.

  1. Install Flx Modernize from wordpress.org and activate it. Until a Render URL is saved it sends nothing anywhere.
  2. Have a Flx Render service for your theme: run the package yourself, or have it hosted for you.
  3. In wp-admin, open Flx Modernize and click Generate signing key. Copy the value it shows (once) into the Render service's FLX_RENDER_SIGNING_KEYS, and redeploy the service.
  4. Enter the Render service URL and save.
  5. Click Test connection. It checks that the service is reachable and that it accepts the signing key, and says what to fix if not.
  6. Check a page: open the site in a private window. The page HTML links …/static/styles.css on your Render service domain and the response has Cache-Control: private, no-store.

Prefer files? Every setting can be defined in wp-config.php instead (see Settings); a constant takes priority and the screen then shows that setting read-only.

Settings

Setting On the Flx Modernize screen Or in wp-config.php Notes
Render URL Render URL (screen only) Empty by default; http or https only
Signing key ID Signing key ID, or Generate signing key FLX_MODERNIZE_RENDER_KEY_ID Letters, digits, _ and -
Signing secret Signing secret, or Generate signing key FLX_MODERNIZE_RENDER_SIGNING_SECRET At least 16 characters, no spaces or commas; generated ones are 64 hex characters
Store pages WooCommerce → Store pages FLX_MODERNIZE_WOOCOMMERCE Shown when WooCommerce is active. See WooCommerce stores
Logged-in customers WooCommerce → Logged-in customers FLX_MODERNIZE_LOGGED_IN_CUSTOMERS Needs Store pages
Edge cache time Edge caching → Edge cache time FLX_MODERNIZE_EDGE_TTL Seconds, 60–3600; empty or 0 means off. See Edge caching
Store pages in the edge cache Edge caching → Store pages in the edge cache FLX_MODERNIZE_STORE_EDGE_CACHE Since 1.13.0, off by default. Needs Store pages, an edge cache time and the Cloudflare purge. See Edge caching
Cloudflare purge Cloudflare zone ID and API token FLX_MODERNIZE_CLOUDFLARE_ZONE_ID, FLX_MODERNIZE_CLOUDFLARE_API_TOKEN Optional; a token with only Zone → Cache Purge

Constants win over the screen, and a setting fixed by a constant is shown read-only. The screen never shows a saved secret or token again; leaving that field empty keeps it.

Where the secret lives. Saved on the screen, the signing secret and the Cloudflare token are stored in the WordPress database (not loaded on every request), like most plugins' API keys: anyone with database access or a database backup can read them. For stronger protection, define them in wp-config.php instead.

Signing

With a key ID and secret configured, every request to the Render service carries five headers: X-Flx-Render-Protocol, -Key-Id, -Timestamp, -Nonce and -Signature. The signature is a lowercase hex HMAC-SHA256 of a canonical string built from the method, path, query, timestamp, nonce and a hash of the body.

On the Render service, set the same pair as FLX_RENDER_SIGNING_KEYS=keyId:secret and FLX_RENDER_AUTH_MODE=enforce. It then rejects unsigned requests, unknown keys, bad signatures, replayed nonces and timestamps more than 300 seconds off, all with HTTP 401. Use one key per site.

Generate signing key on the Flx Modernize screen creates a key ID (from your site's host name) and a 64-character secret, and shows keyId:secret once for the Render service. Generating again replaces the key, and the Render service rejects the site until it has the new one. To make a secret yourself, use openssl rand -hex 32.

REST endpoints

The Render service fetches the site's theme CSS from these public, read-only endpoints. They serve CSS that any visitor's browser could already see.

Endpoint Returns
/wp-json/flx-modernize/v1/health plugin status
/wp-json/flx-modernize/v1/global-styles?v=<hash> the theme's computed global styles CSS
/wp-json/flx-modernize/v1/theme-assets/fonts?v=<hash> the theme's @font-face CSS

If your CDN or firewall challenges automated traffic (Cloudflare's Bot Fight Mode, for example), allow the Render service to reach these endpoints, or pages render without the theme CSS.

The filter

// Keep a landing page on normal WordPress.
add_filter( 'flx_modernize_should_render', function ( $should_render ) {
	return is_page( 'campaign' ) ? false : $should_render;
} );

Return false to keep WordPress for the request. Only a literal true keeps Flx on.

What your plugins print in the page head and footer (wp_head and wp_footer) is sent to the Render service and shown on Flx pages:

  • Kept: the <title>, SEO <meta> tags (description, robots, Open Graph, Twitter), canonical, alternate, prev, next and shortlink links, JSON-LD structured data, plugin or external scripts such as analytics, and plugin stylesheets and <style> blocks (since 1.6.0).
  • WordPress scripts plugins need: when a plugin script depends on jQuery or another WordPress script (wp-i18n, wp-hooks, ...), that script comes along too, in the order WordPress prints it (since 1.6.0). The same goes for WordPress stylesheets a plugin stylesheet depends on, such as Dashicons.
  • Left out: WordPress's own and the theme's styles and scripts that no plugin needs (the Render service already styles the theme and its blocks), script modules, emoji, and any other markup.
  • Visitor data: the output is captured as an anonymous visitor, with cookies and the query string hidden (the search words excepted), so nothing about the visitor is sent.
  • Fallback: when the Render service fails, the visitor gets the page exactly as WordPress renders it without Flx (fetched fresh from the site itself).
  • Limits: each part may be up to 64 KB. If styles push a part over that, it is sent without styles and WordPress scripts; if it is still too big, it is left out, and the renderer uses its own title, description and canonical.
  • Checked with: Yoast SEO, Contact Form 7 (styles, script, form validation; the form looks as on WordPress) and Easy FancyBox (jQuery lightbox).

To turn it off:

add_filter( 'flx_modernize_head_footer_output', '__return_false' );

Edge caching

Off by default. When it is on, Flx pages that are the same for every visitor can be stored by your CDN, so most visits are answered without reaching WordPress. Turn it on with Edge cache time on the Flx Modernize screen, with the optional Cloudflare zone ID and API token for purging, or in wp-config.php:

// wp-config.php
define( 'FLX_MODERNIZE_EDGE_TTL', 300 ); // seconds a CDN may keep a page (60-3600)
define( 'FLX_MODERNIZE_CLOUDFLARE_ZONE_ID', '<your zone ID>' );   // optional: purge on change
define( 'FLX_MODERNIZE_CLOUDFLARE_API_TOKEN', '<purge-only token>' );
  • Cached: a page, a single post, the blog home page, and category and tag archives, when the request has no query string and nothing on the site sets a cookie. They are sent Cache-Control: public, max-age=0, s-maxage=<TTL>: the CDN keeps them for the TTL and browsers check again on every visit.
  • Never cached: search results, the 404 page, any URL with a query string (including utm_ links and previews), the fallback page, and everything WordPress renders itself: logged-in users, password-protected, private and draft content.
  • Purge: with a Cloudflare zone ID and API token (screen or constants), the plugin clears the whole site from Cloudflare's cache after any change that can show on a page: a post or page published, updated, unpublished or deleted, menus, categories and tags, the Site Editor and Customizer, site title and other page settings, plugins turned on or off. One purge per save. If a purge fails, pages update when the TTL runs out. The token is never logged.
  • Your CDN must follow the header. On Cloudflare, add a Cache Rule for your host: cache eligible when the path does not start with /wp-, the query string is empty, and no wordpress_logged_in_, wordpress_sec_, wp-postpass_ or comment_author_ cookie is present; Edge TTL "Use cache-control header if present, bypass cache if not"; Browser TTL respect origin. Then only what the plugin marks public is stored.
  • Store pages (since 1.13.0, opt-in): with Store pages in the edge cache on (or FLX_MODERNIZE_STORE_EDGE_CACHE), the Flx shop, product category, tag and product pages are cached too, for at most 300 seconds whatever the edge cache time. It needs the Cloudflare zone ID and token, so stock and price changes can clear the cache. Never cached: shoppers with a WooCommerce cart or session cookie, logged-in customers, Cart, Checkout and My account, and every store page while WooCommerce geolocates visitors. Stock, stock status and visibility, product saves, scheduled sales, orders reaching processing, tax rates and WooCommerce settings purge through one WP-Cron event about 30 seconds later, so a checkout never waits for Cloudflare. Add woocommerce_items_in_cart, woocommerce_cart_hash and wp_woocommerce_session_ to the Cache Rule's cookie bypass before turning it on. Leave it off, or return false from flx_modernize_store_route_cacheable, if a plugin shows prices, currency or products per visitor.
  • Stale-while-revalidate (since 1.14.0, ADR-0024): cached pages also get Cloudflare-CDN-Cache-Control: max-age=<TTL>, stale-while-revalidate=<window>, so when a copy runs out Cloudflare serves it once more while it fetches a fresh one, and no visitor waits. A purge still removes the copy at once. Window: one hour for pages, posts and archives with the Cloudflare purge set up, the TTL without it, 60 seconds for store pages; a failed purge is retried once, and changing the edge cache time or the Cloudflare settings purges; the flx_modernize_stale_while_revalidate filter changes it (0 turns it off). Cache-Control is unchanged, and other CDNs ignore the header.
  • Check it: open a post twice in a private window; the second response shows cf-cache-status: HIT. Edit the post, and the next visit shows MISS with the change.

To turn it off, empty the edge cache time (or remove FLX_MODERNIZE_EDGE_TTL); pages are private, no-store again at once (cached copies expire within the TTL).

Site language

Every payload carries the site language (language, the value WordPress prints in <html lang>, e.g. en-US), so Flx pages have the same <html lang> as native ones. It is a site setting, never visitor data. Renderer package 1.3.0 and later use it; older renderers ignore it and say en.

Post pages

Post payloads also carry what the theme shows around a post: the author's archive link, the categories and tags, the previous and next posts, and the four latest posts for "More posts". All of it is public site content, built as an anonymous visitor. Renderer package 1.5.0 and later show it; older renderers ignore it.

Comments

Post pages carry the theme's comments section (comments_html): approved comments and the reply form, rendered by WordPress for an anonymous visitor with the visitor's cookies hidden, so it is the same for everyone. The form is WordPress's own, so anti-spam and consent plugins that hook it keep working, and it posts to WordPress as usual. The filter flx_modernize_comments_html can change or remove the section. With edge caching on, approving or editing a comment, or changing a comment setting, purges the cache. Renderer package 1.4.0 and later show it.

The header menu comes from the theme header's Navigation block. Custom, page, post and category links are supported, and sub-menus up to three levels deep; a sub-menu's own link is optional. Page and post links with an ID use the item's current permalink and are dropped if the item is not published. Sub-menus open on hover and keyboard focus (CSS only, no script) and are always open in the phone menu.

WooCommerce stores

Since 1.8.0, and off unless a site opts in: on the Flx Modernize screen (WooCommerce → Store pages, since 1.12.0) or in wp-config.php. It needs the Storefront theme and the Storefront renderer, or (since 1.11.0) the Astra theme (4.14, without a child theme) and an Astra renderer built for the site. On any other theme, or with a template that wasn't reviewed, store pages stay normal WordPress.

Constant (screen setting) What it does
FLX_MODERNIZE_WOOCOMMERCE (Store pages) The shop, product categories and tags, products and Storefront's home page go through Flx, including for shoppers with a cart. On Astra, also the store's pages on the default page template, with Astra's header and footer as the site prints them
FLX_MODERNIZE_WOOCOMMERCE_SHELL (wp-config.php only) The Cart and a guest's My account get the renderer's header and footer around WooCommerce's own forms (WordPress 6.9 or later)
FLX_MODERNIZE_WOOCOMMERCE_SHELL_CHECKOUT (wp-config.php only) The same for Checkout. If you take real payments, ask your payment provider or assessor first
FLX_MODERNIZE_LOGGED_IN_CUSTOMERS (Logged-in customers) Since 1.10.0: logged-in customers get the same catalogue pages as a guest. Leave it off if prices or products differ per customer (memberships, wholesale or role-based prices)

Every visitor gets the same catalogue page, built with an empty cart and no customer data; WooCommerce's scripts fill in the cart in the browser. For the Cart, Checkout and My account, WordPress fills in the page on your server, and their contents are never sent. Logged-in customers get normal WordPress unless the store turns on logged-in customers; even then only the catalogue pages go through Flx for them, nothing about them is sent, and anyone who can edit content or run the store always gets normal WordPress. Flx Render (Storefront) has the full list of what goes where.

Rollback

Deactivate the plugin. Every visitor gets normal WordPress immediately; nothing else changes.

Known limits in 1.14.0

  • Twenty Twenty-Five, Storefront and Astra (4.14) for WooCommerce stores, and Hello Elementor (below) only.
  • Elementor: supported on the Hello Elementor theme only (Elementor 4.3 and Hello Elementor 3.5, free versions), for pages built with Elementor on the "Elementor Full Width" or "Elementor Canvas" template; every other page of such a site stays normal WordPress. The renderer for an Elementor site is built for that site by Flx; it is not a download.
  • WooCommerce store pages are rendered through Flx only on Storefront and Astra, with the opt-in. On Astra, the renderer is built for the site by Flx; it is not a download. On a Twenty Twenty-Five site with WooCommerce, the header on Flx pages lacks the mini-cart and account icons WooCommerce adds to the theme's header.
  • Logged-in visitors always see normal WordPress, except logged-in customers on the catalogue pages of a Storefront or Astra store that opted in.
  • A comment's reply link opens normal WordPress instead of moving the form in place.
  • A sub-menu's arrow button does not toggle it by itself; hover and keyboard focus do. Page List blocks in the header menu are not rendered.
  • Plugin styles that target theme or block markup the Render service draws differently may not match. A plugin's style or script that has no file of its own (only inline code) is left out unless another plugin file depends on it.
  • Post lists show each post's excerpt; the theme shows the full post.
  • Edge caching purges the whole site on Cloudflare only; with another CDN, pages update when the TTL runs out.
  • The "Skip to content" link is in English on every site.

Published from rickey29/twenty-twenty-five at commit 72c5424 · Flx Modernize 1.14.0 · Flx Render 1.14.0