View Categories

FastPixel – Hooks

3 min read

FastPixel provides WordPress action hooks that allow developers to programmatically trigger cache purges and react to cache events. This is useful when integrating FastPixel with custom plugins, WooCommerce, ACF, or any workflow that modifies content outside the standard WordPress editor.

Trigger Hooks #

Use these hooks to initiate a cache purge from your own code.

fastpixel/purge/all #

Purges the entire site cache. Equivalent to clicking “Purge All Cache” in the FastPixel admin panel.

Parameters: None

Example:

do_action('fastpixel/purge/all');

Use case – Purge everything when ACF options page is saved:

add_action('acf/save_post', function($post_id) {
    if ($post_id === 'options') {
        do_action('fastpixel/purge/all');
    }
});

fastpixel/purge/single #

Purges the cache for a single post, page, or taxonomy term.

Parameters:

ParameterTypeRequiredDescription
idintYesThe post ID or term ID to purge
typestringNo'posts' or 'taxonomies'. Auto-detected if omitted.

Examples:

// Purge a post (type is auto-detected)
do_action('fastpixel/purge/single', ['id' => 123]);

// Purge a taxonomy term
do_action('fastpixel/purge/single', ['id' => 45]);

// Explicitly specify the type
do_action('fastpixel/purge/single', ['id' => 123, 'type' => 'posts']);
do_action('fastpixel/purge/single', ['id' => 45, 'type' => 'taxonomies']);

Use case – Purge a WooCommerce product when stock changes:

add_action('woocommerce_product_set_stock', function($product) {
    do_action('fastpixel/purge/single', ['id' => $product->get_id()]);
});

Use case – Purge a post when its custom meta is updated:

add_action('updated_post_meta', function($meta_id, $post_id, $meta_key) {
    if ($meta_key === 'my_custom_field') {
        do_action('fastpixel/purge/single', ['id' => $post_id]);
    }
}, 10, 3);

fastpixel/purge/url #

Purges the cache for a specific URL. Useful for pages that aren’t tied to a post ID, such as custom routes or archive pages.

Parameters:

ParameterTypeRequiredDescription
$urlstringYesThe full URL to purge

Examples:

// Purge a specific URL
do_action('fastpixel/purge/url', 'https://example.com/my-landing-page/');

// Purge the homepage
do_action('fastpixel/purge/url', home_url('/'));

Use case – Purge a custom archive page when a related CPT is saved:

add_action('save_post_event', function($post_id) {
    if (get_post_status($post_id) === 'publish') {
        do_action('fastpixel/purge/url', home_url('/events/'));
    }
});

After-Purge Hooks #

Use these hooks to react after a cache purge has already occurred. These are useful for logging, sending notifications, or chaining additional actions.

fastpixel/purge_all #

Fires after the entire cache has been purged.

Parameters: None

Example:

add_action('fastpixel/purge_all', function() {
    error_log('FastPixel: full cache was purged at ' . current_time('mysql'));
});

fastpixel/backend/purged/single/post #

Fires after a single post’s cache has been purged.

Parameters:

ParameterTypeDescription
$postWP_PostThe WordPress post object that was purged

Example:

add_action('fastpixel/backend/purged/single/post', function($post) {
    error_log('FastPixel: cache purged for post #' . $post->ID . ' (' . $post->post_title . ')');
});

fastpixel/backend/purged/single/term #

Fires after a taxonomy term’s cache has been purged.

Parameters:

ParameterTypeDescription
$termWP_TermThe WordPress term object that was purged

Example:

add_action('fastpixel/backend/purged/single/term', function($term) {
    error_log('FastPixel: cache purged for term #' . $term->term_id);
});

fastpixel/backend/purged/single/by_url #

Fires after a specific URL’s cache has been purged.

Parameters:

ParameterTypeDescription
$urlstringThe URL that was purged

Example:

add_action('fastpixel/backend/purged/single/by_url', function($url) {
    error_log('FastPixel: cache purged for URL ' . $url);
});

en_USEnglish