# ForgeCache WP-CLI Commands and Developer Hooks

> Clear and purge the ForgeCache cache from WP-CLI or your own code: wp forgecache clear, purge-url, purge-post, webp and agent-tier, plus purge actions.

- Canonical: <https://royalplugins.com/support/forgecache/wp-cli-commands/>
- Last updated: 2026-11-26
- HTML version: <https://royalplugins.com/support/forgecache/wp-cli-commands/>

---

ForgeCache adds `wp forgecache` commands to WP-CLI for clearing the cache, purging single pages or posts, cleaning up WebP files and checking the Agent Tier. Developers can also clear or purge from their own code with three WordPress actions, and react to purges with four more. Every command and hook below is part of ForgeCache 2.1.44 or later.

## Commands at a glance

| Command | What it does |
| --- | --- |
| `wp forgecache clear` | Clears this site’s whole cache, like **Clear Cache** in the admin bar. |
| `wp forgecache purge-url <url>...` | Purges the cached page of one or more addresses. |
| `wp forgecache purge-post <id>...` | Purges one or more posts the way saving them does. |
| `wp forgecache webp orphans` | Finds WebP files whose original image is gone, and optionally moves them aside. |
| `wp forgecache agent-tier <command>` | Status, purge, test and llms.txt commands for the Agent Tier. |

Run every command from the WordPress folder, or add `--path=/path/to/wordpress`. Run them as the same system user as your web server (for example `sudo -u www-data wp ...`) so the cache files stay writable for the site.

## wp forgecache clear

Clears everything for this site: every cached page, the CDN (when the CDN is set to purge automatically), the object cache and ForgeCache’s stored lookups. The output says how many cached files were removed and what happened at the CDN.

```
wp forgecache clear
wp forgecache clear --url=shop.example.com
wp forgecache clear --network
```

- **Multisite.** Without options the command clears the site WP-CLI runs on. Pick another site with the global `--url=<site>` parameter.
- **`--network`** clears every site of a multisite network, each site’s CDN with that site’s own settings, and prints one line per site. On a single site it stops with an error.
- The command exits with an error when the cache could not be cleared or the CDN purge failed, so scripts can check the exit code.

## wp forgecache purge-url

Purges every cached copy of each page you name (http and https, visitors and AI agents, each spelling of the address). Other pages stay cached. Give full addresses on this site, starting with `http://` or `https://`.

```
wp forgecache purge-url https://example.com/pricing/
wp forgecache purge-url https://example.com/ https://example.com/blog/
```

- **CDN.** When the CDN is set to purge automatically, it is told once at the end of the command: each address once, up to 50 addresses. Above 50, the whole CDN cache is purged in one call instead. The output says what was sent.
- **Other sites.** An address that belongs to another site of a network is refused. Run the command for that site with `--url=<that site>`.
- The command exits with an error when an address is refused or the CDN could not be told.

## wp forgecache purge-post

Purges a post the way saving it does: the post’s own page, the home page and the archive of its post type. Works for posts, pages and other content types.

```
wp forgecache purge-post 42
wp forgecache purge-post 42 57 103
```

The command exits with an error when an ID is not a post.

## wp forgecache webp orphans

Finds WebP files in the media library folders that no image uses any more, such as copies whose JPEG or PNG was deleted. WebP files that are media items themselves, other plugins’ folders and (on a network) other sites’ folders are never touched.

```
wp forgecache webp orphans                     # count them, list the first 20
wp forgecache webp orphans --delete --dry-run  # list every file, change nothing
wp forgecache webp orphans --delete            # move them aside
```

`--delete` moves the files to a private folder inside uploads, where they are kept for 30 days and then deleted, so you can still get a file back. The same cleanup is available from the **Media** tab in **ForgeCache → Settings**.

## wp forgecache agent-tier

```
wp forgecache agent-tier status
wp forgecache agent-tier purge
wp forgecache agent-tier test --ua="ClaudeBot/1.0" --uri="/blog/post/"
wp forgecache agent-tier rebuild-llms-txt
```

- **`status`** shows whether the Agent Tier is on, where llms.txt and llms-full.txt are served, and the last 24 hours of traffic: total requests, bot share, hit rates and the most matched bots.
- **`purge`** deletes the cached copies served to AI agents. The pages cached for people stay.
- **`test --ua=<user-agent>`** shows whether a user agent counts as a bot, which pattern matched, and which cache file a request for `--uri` (default `/`) would use.
- **`rebuild-llms-txt`** builds the llms.txt output now and prints its size, so you can check it after bulk content changes.

## Clear or purge from your own code

Fire one of these WordPress actions from a theme, plugin or must-use plugin. When ForgeCache is not active nothing happens, so the call is safe to leave in place.

```
// Clear this site's whole cache (pages, CDN when it purges automatically,
// object cache), like Clear Cache in the admin bar.
do_action( 'forgecache_purge_all' );

// Purge one page of this site: every scheme and visitor variant.
do_action( 'forgecache_purge_url', 'https://example.com/pricing/' );

// Purge a post the way saving it does: its page, the home page and its
// post type archive. Takes a post ID or a WP_Post object.
do_action( 'forgecache_purge_post', 123 );
```

| Action | Argument |
| --- | --- |
| `forgecache_purge_all` | None. |
| `forgecache_purge_url` | A full http or https address on this site. An address of another site of a network is refused. |
| `forgecache_purge_post` | A post ID (number) or a `WP_Post` object. |

Actions return nothing. A request that cannot be carried out (an address on another site, an ID that is not a post) is skipped; with `WP_DEBUG` on, an argument that is not a post ID or post object is reported as incorrect usage. Purges run one after another as often as you like. ForgeCache only skips a purge that is already running for the same site and target, or one started more than 20 levels deep from inside other purges, so code that listens to the purge actions can’t loop forever.

### Getting a result back

If your code needs to know what happened, call the same purges directly and check the result. Guard the call so it does nothing when ForgeCache is not active:

```
if ( class_exists( 'ForgeCache_Purge' ) ) {
    $deleted = ForgeCache_Purge::purge_url( 'https://example.com/pricing/' );
    if ( is_wp_error( $deleted ) ) {
        error_log( $deleted->get_error_message() );
    }
}
```

- `ForgeCache_Purge::purge_all()` returns `true`, or a `WP_Error` when the clear did not run.
- `ForgeCache_Purge::purge_url( $url )` returns the number of cached files deleted (`0` when the page was not cached), or a `WP_Error` explaining why the address was refused.
- `ForgeCache_Purge::purge_post( $post )` returns `true`, or a `WP_Error` when the ID is not a post.

## React when the cache is cleared

ForgeCache fires these actions after it clears or purges, whether the purge came from the admin, a post save, WP-CLI or your own code. Use them to clear another cache layer you run.

| Action | When it fires and its arguments |
| --- | --- |
| `forgecache_all_cache_cleared` | After every cached page of the site was deleted. No arguments. |
| `forgecache_cache_purged` | After a full clear that also emptied the object cache. No arguments. |
| `forgecache_post_cache_cleared` | After a post’s pages were purged. `$post_id` (int) and `$old_urls` (array of addresses the post moved away from, at most 50). |
| `forgecache_url_cache_cleared` | After one address was purged on request. `$url` (string), `$deleted` (number of files deleted) and `$addresses` (the address in each spelling a CDN may hold). |

```
add_action( 'forgecache_url_cache_cleared', function ( $url, $deleted, $addresses ) {
    foreach ( $addresses as $address ) {
        my_edge_cache_purge( $address ); // your own purge function
    }
}, 10, 3 );
```

Related

- [**Connecting Cloudflare**](https://royalplugins.com/support/forgecache/connecting-cloudflare/) and [**Connecting BunnyCDN**](https://royalplugins.com/support/forgecache/connecting-bunnycdn/): set up automatic CDN purges
- [**ForgeCache documentation**](https://royalplugins.com/support/forgecache/): the Agent Tier, page caching and every other feature

[Back to ForgeCache Support](https://royalplugins.com/support/forgecache/)
[ForgeCache Plugin Page](https://royalplugins.com/forgecache/)
