Skip to content

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 cached counts .html files, so each variant of a URL counts once.
  • Features on lists the settings whose value is 1. Choice and list settings are not shown.
  • The Preload line 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> or Nothing 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.
  • --minified clears the combined and minified files and, because cached pages reference those files, purges every page as well. wp bb-cache purge --minified and wp bb-cache purge --all --minified do 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 --sync the URLs are queued and fetched by WP-Cron in batches of 8, five seconds apart. The command prints Queued <n> URLs for background preload.
  • With --sync each URL is fetched in turn and printed as [<i>/<total>] <url>.
  • The sitemap is the sitemap_url setting, or the first of /sitemap_index.xml, /sitemap.xml and /wp-sitemap.xml that answers 200. 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_mobile is 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.php is 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.php currently belongs to another plugin.
  • If wp-config.php is not writable the last line reads wp-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
  • status prints the critical CSS folder and each .css file in it with its size and age, or (none).
  • targets prints, 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_load hook rather than at plugin load. Compiling a WP_CLI_Command subclass 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 purge with the Cloudflare purge mirror on. wp bb-cache cloudflare purge talks to Cloudflare only.