Scheduled snippets Pro
Pro · This feature is part of Snipfire Pro. Plans
A PHP snippet can run on a schedule instead of on a hook: a nightly clean-up, an hourly stock sync, a weekly report email. Snipfire runs it with WP-Cron, keeps a run log of every run, and switches it off if it fails, as on any page.
Put a snippet on a schedule
- Open a PHP snippet. Under How it runs, choose On a schedule.
- Under Runs, choose Every hour, Twice a day, Once a day, Once a week or Every N minutes. For Every N minutes, set Minutes between runs (5 or more).
- Optionally set Starting: the date and time of the first run, in your site's time zone. Optional. Without it, the first run is one interval after the snippet is switched on. A start time in the past sets the rhythm: a daily snippet starting yesterday at 03:00 runs every day at 03:00.
- Switch it on (Active) and save.
The settings panel then shows Next run: with the date and time, and the sidebar marks the snippet as running on a schedule. A switched-off snippet isn't scheduled: Not scheduled: the snippet is switched off.
The code runs as it is, once per run, with WordPress fully loaded. Write it like code for Only when I click Run:
// Remove expired transients from the database.
delete_expired_transients( true );
echo 'Expired transients removed.';
Anything the snippet prints is kept in the run log.
The run log
Run log (in the settings panel, or ⋯ → Run log) lists the last 50 runs, newest first:
- when it ran and what started it: the schedule, Run now (and who clicked it) or WP-CLI,
- how long it took and its peak memory,
- the result: OK, or the error with its line,
- what it printed (the first 10 KB). Click a run to see its output or error.
The settings panel also shows the last run: Last run … : OK or failed.
The run log is kept in files next to your snippets (wp-content/snipfire/runs/), not in the database.
Run now
Run now runs the saved version once, straight away, and records it in the run log. Save your changes first.
Run now runs on Snipfire's own request, where your other snippets aren't loaded. Runs from the schedule and from WP-CLI load them as usual. If the snippet relies on a function another snippet declares, test it with WP-CLI.
When a run fails
A scheduled run goes through the same crash protection as a page view. If the snippet throws an error or causes a fatal error, it's switched off, the error is recorded (in the run log, on the snippet and in the activity log), and it isn't scheduled again until you fix it and switch it back on. See How Snipfire keeps your site safe.
Each run has a time limit of 60 seconds of processing time (not on WP-CLI), so a runaway loop can't tie up your server. Only one run of a snippet happens at a time. Developers can change the limit with the snipfire_schedule_time_limit filter: see PHP hooks.
WP-Cron: runs need visitors, or a real cron job
WordPress runs scheduled tasks (WP-Cron) when someone visits the site. On a quiet site, a run can be late; at night, it may wait for the first visitor in the morning. A real cron job calling wp-cron.php makes them punctual.
For exact times, ask your host for a cron job that calls your site's wp-cron.php every few minutes, for example:
*/5 * * * * curl -s https://example.com/wp-cron.php > /dev/null
If wp-config.php has define( 'DISABLE_WP_CRON', true );, WordPress doesn't run WP-Cron on page views at all, and the settings panel warns you: scheduled snippets then run only if a real cron job calls wp-cron.php.
Good to know
- Conditions aren't checked on scheduled runs: there's no page or visitor to check them against. Put any checks in the code.
- Only PHP snippets can run on a schedule.
- Nothing runs while safe mode is on, or with
SNIPFIRE_DISABLE_PHP.SNIPFIRE_SAFE_MODEinwp-config.phpstops scheduled runs; your safe mode link stops Run now in your browser. See Locking Snipfire down. - Changing the schedule is a save like any other: it's in the snippet's history and the activity log. Snipfire keeps one WP-Cron event per scheduled snippet and moves or removes it when you change the schedule, switch the snippet off or delete it. Deactivating Snipfire Pro removes them all.
- Who can use it: changing a PHP snippet, and Run now, need full Snipfire access. People with View only access can read the run log.
- Without Snipfire Pro, the snippet keeps its schedule but doesn't run, and the editor says it needs Snipfire Pro.
- Exporting as a plugin: scheduled snippets can't be exported as a plugin.
- The Scheduled task generator is another way to run code on WP-Cron, without Pro. A scheduled snippet adds the run log, Run now, the time limit and crash protection.
From the command line
wp snipfire create --title="Nightly clean-up" --file=cleanup.php \
--run=schedule --schedule='{"every":"daily","start":"2026-10-01 03:00"}' --active
wp snipfire update 12 --schedule='{"every":"minutes","minutes":15}'
wp snipfire schedule list # every scheduled snippet, with its next and last run
wp snipfire schedule run 12 # run it now and record it
wp snipfire schedule log 12 --output # its run log, with each run's output
every is hourly, twicedaily, daily, weekly or minutes. See WP-CLI and the REST API.
Something unclear or missing? Tell us