WP-CLI#
BB Cache registers one command, wp bb-cache, with the subcommands below. The class is BB_Cache_CLI in
inc/class-cli.php.
wp bb-cache status
wp bb-cache purge [<url>...] [--all] [--minified]
wp bb-cache preload [--sync]
wp bb-cache config
wp bb-cache htaccess <on|off>
wp bb-cache critical <targets|status>
wp bb-cache cloudflare <verify|purge|check|log> [<url>...]
WP-CLI requests are never served from or stored in the page cache.
status#
Shows the cache state. No arguments.
wp bb-cache status
Example output:
Pages cached: 128 (9 MB)
Drop-in: ok | WP_CACHE: on | .htaccess: absent
Features on: page_cache, cache_mobile, minify_css, concat_css, combine_google_fonts, minify_js, preload_links, disable_emoji
Preload: 40/128 done, 88 pending
Warning: Conflicting cache plugins active: WP Rocket
Pages cachedcounts.htmlfiles, so each variant of a URL counts once.Features onlists the settings whose value is1. Choice and list settings are not shown.- The
Preloadline appears once a preload has been queued. - The warning appears when a known page cache plugin is active.
purge#
Purges cached pages.
| Argument | Meaning |
|---|---|
[<url>...] |
URLs to purge. Each is purged recursively: the URL's variants and everything stored beneath its path. |
[--all] |
Purge every page. |
[--minified] |
Also clear the combined and minified CSS and JS files. |
wp bb-cache purge
wp bb-cache purge --all --minified
wp bb-cache purge https://example.com/pricing/ https://example.com/blog/
Behaviour:
- With no arguments at all, every page is purged.
- For each URL the command prints
Purged <url>orNothing cached for <url>. - Purging the home URL is recursive like any other, so
wp bb-cache purge https://example.com/removes every page stored for that host. --minifiedclears the combined and minified files and, because cached pages reference those files, purges every page as well.wp bb-cache purge --minifiedandwp bb-cache purge --all --minifieddo the same thing.- When the Cloudflare purge mirror is on, the queued edge purges are sent before the command returns, and each call is
reported as
Cloudflare: purged 2 URL(s).,Cloudflare: purged everything.or a warning with Cloudflare's error.
preload#
Warms the cache from the sitemap.
| Argument | Meaning |
|---|---|
[--sync] |
Fetch every URL now instead of queuing for cron. |
wp bb-cache preload
wp bb-cache preload --sync
- Without
--syncthe URLs are queued and fetched by WP-Cron in batches of 8, five seconds apart. The command printsQueued <n> URLs for background preload. - With
--synceach URL is fetched in turn and printed as[<i>/<total>] <url>. - The sitemap is the
sitemap_urlsetting, or the first of/sitemap_index.xml,/sitemap.xmland/wp-sitemap.xmlthat answers200. Sitemap indexes are followed. If no sitemap is found, only the home page is fetched. - Each URL is requested once with a desktop user agent and, when
cache_mobileis on, once with a phone user agent. - The pages are fetched over HTTP from the site's public address, so the server must be able to reach itself.
config#
Rewrites config.php, reinstalls the drop-in and sets WP_CACHE. No arguments.
wp bb-cache config
Example output:
config.php written.
advanced-cache.php installed.
WP_CACHE set.
config.phpis rewritten from the saved settings, and the host list is derived again from the site address.- The drop-in is written even if
advanced-cache.phpcurrently belongs to another plugin. - If
wp-config.phpis not writable the last line readswp-config.php not writable; set WP_CACHE yourself.
Use it after copying the plugin to a server by hand, after a database import that changed the site address, or when a notice reports the drop-in as missing or stale.
htaccess#
Writes or removes the Apache rewrite block.
| Argument | Meaning |
|---|---|
on or off (required) |
on writes the block; any other value removes it. |
wp bb-cache htaccess on
wp bb-cache htaccess off
Prints Rules written., Rules removed. or .htaccess not writable. The command does not change the
htaccess_rules setting. The next settings save writes or removes the block according to the setting, so turn the
setting on as well if the block should stay.
critical#
Critical CSS helpers.
| Argument | Meaning |
|---|---|
targets or status (required) |
targets prints JSON of key to sample URLs. status lists the generated files. |
wp bb-cache critical status
wp bb-cache critical targets > critical-targets.json
statusprints the critical CSS folder and each.cssfile in it with its size and age, or(none).targetsprints, for each key of the legacy per-template scheme (home,tpl-<slug>,page,single-<post type>,archive-<post type>,blog), up to three sample URLs. It is meant as input for a critical CSS generator. See Critical CSS.
cloudflare#
Verifies the token, purges the edge, checks what the edge serves, or shows the purge log.
| Argument | Meaning |
|---|---|
verify, purge, check or log (required) |
The action. |
[<url>...] |
URLs for purge, or the one URL for check. |
wp bb-cache cloudflare verify
wp bb-cache cloudflare check https://example.com/pricing/
wp bb-cache cloudflare purge https://example.com/ https://example.com/pricing/
wp bb-cache cloudflare purge
wp bb-cache cloudflare log
| Action | Behaviour |
|---|---|
verify |
Checks that the token is active and tries to read the zone. Exits with an error when the zone ID or token is missing or malformed, or the token is rejected or not active. |
purge |
With URLs: purges exactly those URLs at the edge, 30 per API call. Without URLs: purges everything in the zone. Exits with an error when the zone ID or token is missing. It works whether or not the cf_purge setting is on, and it does not touch the local page cache. |
check |
Fetches the URL (default: the home page) twice and prints one line per request with the HTTP status, cf-cache-status, age, cache-control and x-bb-cache, followed by a verdict. |
log |
Prints the last 20 purge calls: time (UTC), what was purged, the result and up to three sample URLs. |
Example check output:
#1 HTTP 200 cf-cache-status=MISS age=- cache-control="public, max-age=0, s-maxage=900" x-bb-cache=HIT
#2 HTTP 200 cf-cache-status=HIT age=1 cache-control="public, max-age=0, s-maxage=900" x-bb-cache=HIT
Success: The edge serves this URL from cache.
See Cloudflare for the meaning of each result.
Notes#
- The command class is loaded on WP-CLI's
after_wp_loadhook rather than at plugin load. Compiling aWP_CLI_Commandsubclass during plugin load fails on some PHP builds with opcache enabled for the CLI ("Cannot declare class WP_CLI"). - To purge the local page cache and the edge together, use
wp bb-cache purgewith the Cloudflare purge mirror on.wp bb-cache cloudflare purgetalks to Cloudflare only.