Skip to content
StaticScope
Overview
Get StaticScope

Hooks overview

How the build and publish lifecycle works, where to add code and which conventions StaticScope hooks follow.

Developers Updated 21 November 2026 5 min read

StaticScope does the same thing every time you press Build: it finds the URLs, copies them, prepares the files, checks the result and hands the folder to a publisher. Each stage fires actions and filters. That is the extension API. There is no separate framework to learn.

Every hook starts with staticscope_. Add-ons add their own segment, so Sync’s hooks start staticscope_sync_ and GitHub’s start staticscope_github_. If a hook is not in this reference, treat it as private even when you can see it in the source.

Where to put the code

Use a must-use plugin. Create wp-content/mu-plugins/ if it does not exist, then add staticscope-hooks.php. Must-use plugins load on every request, including WP-CLI and cron, and they survive a theme switch. There is nothing to activate.

<?php
add_action( 'staticscope_before_build', function () {
	error_log( 'StaticScope build started at ' . gmdate( 'c' ) );
} );

The trade-off is that a must-use plugin has no off switch in the admin. If you want to disable your code without renaming a file, put the same snippets in a small normal plugin instead. Either is better than functions.php: a theme switch would take the behaviour with it, and a theme switch is exactly when a build needs to behave predictably.

Actions and filters

An action tells you something is about to happen or has happened. A filter hands you a value and expects it back. That is the only distinction that matters day to day.

KindWhat you receiveWhat you returnUse it for
ActionWhatever the call site passesNothingLogging, notifying, writing a file, throwing to stop a step
FilterA value and any extra contextThe value, changed or unchangedURLs, paths, options, markup, permissions

Return the value from every path in a filter. Returning nothing makes the value null, and the option filters cast that to an empty string. A callback that only returns inside an if will blank the setting everywhere else.

Naming

  • Core hooks are staticscope_<thing>, such as staticscope_deploy.
  • Add-on hooks are staticscope_<addon>_<thing>, such as staticscope_sync_media_max_bytes.
  • Option filters are generated as staticscope_option_<optionName>, keeping the option’s camelCase name.

There is one exception to the option rule: staticscope_use_crawl_cache. The option is called useCrawlCaching, but its filter name is hard-coded. A handler on staticscope_option_useCrawlCaching will never run.

Priorities

The default priority is 10. Lower numbers run earlier. Callbacks on the same priority run in the order they were added. The fourth argument to add_action() or add_filter() is how many arguments you accept, and it defaults to 1. A two-argument hook needs 10, 2, or PHP throws an ArgumentCountError when it calls you.

On staticscope_post_process_complete the built-in order matters: HostFiles at 1, Sitemaps at 5, RobotsTxt and LastBuild at 10, then DeadLinks at 20. Pagefind registers at the default 10. Read sitemaps at 6 or later. If you need the folder after every built-in has finished, use 30.

The option-filter convention

CoreOptions::makeOptionSpec() builds staticscope_option_{$name} unless a seventh argument overrides it. The filter is applied on every read, which means during settings rendering, detection, crawling, preparation and publishing. It takes one parameter, the stored value as a string. Password options arrive decrypted. Array options arrive as a newline-delimited string, not an array.

add_filter( 'staticscope_option_deploymentURL', function ( $url ) {
	return 'https://staging.example.com';
} );

These filters do not save anything. The stored option keeps its value, which makes them useful for per-environment overrides that should not appear in the database.

One exception. Crawl caching is filtered as staticscope_use_crawl_cache. There is no staticscope_option_useCrawlCaching filter, so write your handler against the name.

The lifecycle

This is the order when you press Build and Publish on the Overview screen. Scheduled jobs and WP-CLI run the same stages one at a time.

  1. staticscope_addons: filter. Active add-ons append themselves, which is how StaticScope decides what is installed and which one publishes.
  2. staticscope_before_build: action. A build from the Overview is about to start. Throw to stop it.
  3. staticscope_detect: action. URL detection starts. It cannot add URLs by itself.
  4. Detection filters: staticscope_detect_*, staticscope_filenames_to_ignore, staticscope_file_extensions_to_ignore and staticscope_siteinfo.
  5. staticscope_modify_initial_crawl_list: filter. The last chance to add or remove URLs before the queue is filled.
  6. staticscope_crawl: action. The core crawler is attached here and copies the site.
  7. Crawl filters and staticscope_crawling_complete: discovery, pruning, the 404 page, then the summary.
  8. staticscope_post_process_start: action. The copied site is about to be prepared.
  9. staticscope_process_*: actions. One prepared file at a time: HTML, CSS, JS, XML, XSL, JSON and robots.txt.
  10. staticscope_post_process_complete: action. The prepared folder is finished.
  11. Site check: staticscope_check_site and staticscope_runtime_paths.
  12. staticscope_before_publish: action. An existing build is about to be published.
  13. staticscope_deploy: action. The publisher uploads the prepared folder.
  14. staticscope_post_deploy_trigger: action. Notifications and follow-up work.
  15. staticscope_publish_failed: action. A queued stage failed with nobody watching.
StageMain hooksWhat you change there
Registrationstaticscope_addonsWhich add-ons are active and which one publishes
Build requeststaticscope_before_buildStop a build by throwing
Detectionstaticscope_detect, staticscope_detect_*, staticscope_modify_initial_crawl_listWhich URLs enter the queue
Crawlstaticscope_crawl, staticscope_discovered_paths, staticscope_prune_unused_filesWhich files are copied
Crawl endstaticscope_crawling_completeRead the summary; the copy is already on disk
Preparation startstaticscope_post_process_startEdit the copied site before it is prepared
Each filestaticscope_process_html, _css, _js, _xml, _xsl, _json, _robots_txtChange one prepared file in place
Finished sitestaticscope_post_process_completeAdd or change files in the prepared folder
Site checkstaticscope_check_site, staticscope_runtime_pathsWhether the check runs and what it allows
Publishstaticscope_before_publish, staticscope_deployBlock or replace the upload
After publishstaticscope_post_deploy_triggerNotifications, CDN purges, cache clears
Failurestaticscope_publish_failedAlert someone when a queued stage fails

Build versus publish

The two paths do not fire the same hooks. staticscope_before_build runs from the Overview when the steps are build or all. staticscope_before_publish runs from core when the steps are publish, meaning an existing build is being sent. GitHub, S3 and Your server also fire it immediately before they upload, so in practice it covers the Overview and the three official publishers.

staticscope_deploy is the one point every publish path reaches, including wp staticscope deploy. If a check must never be skipped, put it there.

Do not use staticscope_before_build as a publish gate. It does not fire when you publish an existing build, and WP-CLI commands call the stages directly without firing it.

Next