WordPress Plugins
Free Tools
Claude Skills
Resources
Pricing Agencies Support My Account Cart
Support / ForgeCache / WP-CLI Commands

ForgeCache WP-CLI Commands and Developer Hooks

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

CommandWhat it does
wp forgecache clearClears 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 orphansFinds 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

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/

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

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 );
ActionArgument
forgecache_purge_allNone.
forgecache_purge_urlA full http or https address on this site. An address of another site of a network is refused.
forgecache_purge_postA 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() );
    }
}

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.

ActionWhen it fires and its arguments
forgecache_all_cache_clearedAfter every cached page of the site was deleted. No arguments.
forgecache_cache_purgedAfter a full clear that also emptied the object cache. No arguments.
forgecache_post_cache_clearedAfter 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_clearedAfter 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