-
Notifications
You must be signed in to change notification settings - Fork 0
Hooks Reference
Every extension point the plugin fires. All are prefixed gt_performance_.
apply_filters( 'gt_performance_html', string $html, RequestContext $request ): stringThe full response body, immediately before it is stored. This is where every built-in optimizer hooks. Return a non-empty string; anything else is discarded and the original body is used.
$request carries the sanitized method, scheme, host, path, query, cookies, headers and user agent. Every value has already had control characters stripped and lengths bounded.
Fires around each optimization stage, so you can measure or skip individual stages.
The result after the optimization pipeline has run.
apply_filters( 'gt_performance_cache_policy', array $policy ): arrayThe compiled bypass policy — paths, cookies, query parameters — before it is written to the config file and before the Cloudflare expression is compiled from it. Adding a path here protects the origin and the edge in one place.
apply_filters( 'gt_performance_compiled_config', array $config, array $settings ): arrayThe whole compiled configuration written to config.json.php and read by the drop-in on every request. Last chance to change what the drop-in sees.
do_action( 'gt_performance_cache_stored', RequestContext $request, string $hash )After an entry is written.
do_action( 'gt_performance_purged_urls', array $urls, int $count )do_action( 'gt_performance_purged_all', string $scope )$scope is origin or the edge provider.
Queue a purge or a preload for a URL from your own code.
The batch of stale URLs about to be queued for rebuild.
add_filter( 'gt_performance_css_safelist', function ( array $selectors ) {
$selectors[] = '.js-only-modal';
return $selectors;
} );Selector fragments that survive pruning unconditionally.
Stylesheet URL fragments to skip entirely.
add_filter( 'gt_performance_javascript_exclusions', function ( array $fragments ) {
$fragments[] = '/plugins/my-checkout/';
return $fragments;
} );Applies to minify, defer and delay.
Per-image control. Return false to leave a specific image alone.
Whether to generate variants for an attachment, and whether to rewrite a given URL to one.
add_filter( 'gt_performance_private_fragments', function ( array $fragments ) {
$fragments['loyalty_points'] = array(
'fallback' => '—',
'render' => fn() => esc_html( my_points_for_current_user() ),
);
return $fragments;
} );The fallback is cached and served to everyone, so it must be safe for everyone. The renderer runs on a public AJAX endpoint.
Override the built-in fragments without replacing the registry.
do_action( 'gt_performance_loaded' )All modules registered. The right place to add your own filters.
Fires per queue job type, for custom job handling.
Emitted by the Core Forms compatibility module.
| Hook | Schedule |
|---|---|
gt_performance_run_queue |
gtperf_every_minute |
gt_performance_database_cleanup |
daily, gtperf_weekly or gtperf_monthly
|
Custom schedules registered by the plugin: gtperf_every_minute, gtperf_weekly, gtperf_monthly.
GT Performance · GPL-2.0-or-later · Issues and pull requests welcome
Getting started
Caching
Optimization
Delivery
Operations
Reference