Skip to main content

benecaster_benchmarks_fetch_skip

Filter Free

Filters whether a benchmark data refresh attempt should be skipped. Return `true` to abort the refresh silently. Fires on all three refresh paths: the daily scheduled tick (`’cron’`), the lazy first-call seed when no cached data exists (`’lazy’`), and any explicit programmatic caller (`’manual’`).

Returning `true` suppresses the refresh silently — no error is logged, no admin notice is shown, and the REST response falls back to any previously cached benchmark data. The cached data, if any, remains intact. The scheduled event remains active and fires again on the next tick without manual rescheduling. When a refresh is skipped, [benecaster_benchmarks_refreshed](/hooks/benecaster_benchmarks_refreshed/) does not fire.

Examples

Suppress fetches on non-production environments

add_filter(
    'benecaster_benchmarks_fetch_skip',
    function ( bool $skip, string $source ): bool {
        if ( 'production' !== wp_get_environment_type() ) {
            return true;
        }
        return $skip;
    },
    10, 2
);

Suppress scheduled refresh only

add_filter(
    'benecaster_benchmarks_fetch_skip',
    function ( bool $skip, string $source ): bool {
        if ( 'cron' === $source ) {
            return true;
        }
        return $skip;
    },
    10, 2
);

Skip fetches during automated test runs

add_filter(
    'benecaster_benchmarks_fetch_skip',
    function ( bool $skip, string $source ): bool {
        if ( defined( 'MY_PLUGIN_RUNNING_TESTS' ) && MY_PLUGIN_RUNNING_TESTS ) {
            return true;
        }
        return $skip;
    },
    10, 2
);

Notes

The 'lazy' source fires synchronously at request time on the analytics page load path — keep callbacks fast. If you return true for 'cron', the daily tick silently no-ops; you do not need to reschedule it manually.