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.
| Kind | What you receive | What you return | Use it for |
|---|---|---|---|
| Action | Whatever the call site passes | Nothing | Logging, notifying, writing a file, throwing to stop a step |
| Filter | A value and any extra context | The value, changed or unchanged | URLs, 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 asstaticscope_deploy. - Add-on hooks are
staticscope_<addon>_<thing>, such asstaticscope_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.
staticscope_addons: filter. Active add-ons append themselves, which is how StaticScope decides what is installed and which one publishes.staticscope_before_build: action. A build from the Overview is about to start. Throw to stop it.staticscope_detect: action. URL detection starts. It cannot add URLs by itself.- Detection filters:
staticscope_detect_*,staticscope_filenames_to_ignore,staticscope_file_extensions_to_ignoreandstaticscope_siteinfo. staticscope_modify_initial_crawl_list: filter. The last chance to add or remove URLs before the queue is filled.staticscope_crawl: action. The core crawler is attached here and copies the site.- Crawl filters and
staticscope_crawling_complete: discovery, pruning, the 404 page, then the summary. staticscope_post_process_start: action. The copied site is about to be prepared.staticscope_process_*: actions. One prepared file at a time: HTML, CSS, JS, XML, XSL, JSON and robots.txt.staticscope_post_process_complete: action. The prepared folder is finished.- Site check:
staticscope_check_siteandstaticscope_runtime_paths. staticscope_before_publish: action. An existing build is about to be published.staticscope_deploy: action. The publisher uploads the prepared folder.staticscope_post_deploy_trigger: action. Notifications and follow-up work.staticscope_publish_failed: action. A queued stage failed with nobody watching.
| Stage | Main hooks | What you change there |
|---|---|---|
| Registration | staticscope_addons | Which add-ons are active and which one publishes |
| Build request | staticscope_before_build | Stop a build by throwing |
| Detection | staticscope_detect, staticscope_detect_*, staticscope_modify_initial_crawl_list | Which URLs enter the queue |
| Crawl | staticscope_crawl, staticscope_discovered_paths, staticscope_prune_unused_files | Which files are copied |
| Crawl end | staticscope_crawling_complete | Read the summary; the copy is already on disk |
| Preparation start | staticscope_post_process_start | Edit the copied site before it is prepared |
| Each file | staticscope_process_html, _css, _js, _xml, _xsl, _json, _robots_txt | Change one prepared file in place |
| Finished site | staticscope_post_process_complete | Add or change files in the prepared folder |
| Site check | staticscope_check_site, staticscope_runtime_paths | Whether the check runs and what it allows |
| Publish | staticscope_before_publish, staticscope_deploy | Block or replace the upload |
| After publish | staticscope_post_deploy_trigger | Notifications, CDN purges, cache clears |
| Failure | staticscope_publish_failed | Alert 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.