Skip to main content

benecaster_benchmarks_fetch_skip

Filter Premium

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 does not fire.

The return is cast with (bool), so a truthy string or non-zero int aborts the refresh exactly as true does — there is no type error to notice.

Parameters

Name Type Default Description
$skip bool Default false; return true to skip this benchmark refresh
$source string What triggered the refresh — 'manual' by default

Returns: bool

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.

Need this built rather than just documented? See our services →