Documentation / Administrator Guide / Action and filter hooks

Action and filter hooks

Introduction

WordPress hooks are places throughout the WordPress core, plugins, and themes that you can hook into and run your own code in order to improve or extend functionalities without having to edit the core source code. There are two types of hooks: action hooks and filter hooks.

  • Filter hooks allow you to intercept and modify data while it is processed.
  • Action hooks allow you to run code at a specific points in a process.

The Staatic for WordPress plugin provides numerous action and filter hooks enabling developers to integrate with or even extend the Staatic plugin.

This page provides an overview of the most commonly used action and filter hooks as well as the arguments they take and their purpose.

Action hooks

These are the most commonly used action hooks.

staatic_publication_task_before

Triggered during the publication process, before a publication task (e.g. Staatic\WordPress\Publication\Task\CrawlTask) is executed.

Arguments

  1. Staatic\WordPress\Publication\Publication $publication
  2. Staatic\WordPress\Publication\Task\TaskInterface $task

staatic_publication_task_after

Triggered during the publication process, after a publication task (e.g. Staatic\WordPress\Publication\Task\CrawlTask) is executed.

Arguments

  1. Staatic\WordPress\Publication\Publication $publication
  2. Staatic\WordPress\Publication\Task\TaskInterface $task

Filter hooks

General filter hooks

These are the most commonly used general filter hooks.

staatic_site_url

Determines the base URL of the dynamic WordPress site which is used as a starting point when crawling the site and defaults to the result of site_url().

Arguments
  1. string $siteUrl

staatic_debug

Allows the plugin’s debug mode to be enabled. When enabled this results in more detailed error messages as well as additional context information added to publication logs.

Arguments
  1. bool $isDebug

Modifying the publication process

The following filter hooks allow you to change various stages of the publication process, encompassing everything from building the static version of your site to the deploying everything to the configured target.

staatic_publication_tasks

Allows additional publication tasks to be added or existing tasks to be removed from the list of publication tasks executed during a publication.

Publication tasks are responsible for a specific part of the publication process. Examples of publication tasks are:

  • Staatic\WordPress\Publication\Task\SetupTask which ensures that required directories exist and the chosen deployment method has been configured correctly.
  • Staatic\WordPress\Publication\Task\CrawlTask which crawls a set of crawl URLs from the crawl queue.
  • Staatic\WordPress\Publication\Task\FinishTask which finalizes the publication process and updates the publication status.
Arguments
  1. Staatic\WordPress\Publication\Task\TaskInterface[] $tasks

staatic_crawl_url_providers

Allows additional crawl URL providers to be added or existing providers to be removed from the list of crawl URL providers executed during a publication.

Crawl URL providers are used to provide the initial list of URLs to be crawled to the crawler component. Examples of crawl URL providers are:

  • Staatic\Crawler\CrawlUrlProvider\EntryCrawlUrlProvider which provides the homepage URL.
  • Staatic\Crawler\CrawlUrlProvider\PageNotFoundCrawlUrlProvider which provides the 404 page not found URL.
  • Staatic\Crawler\CrawlUrlProvider\AdditionalUrlCrawlUrlProvider which provides a list of additional URLs.
Arguments
  1. Staatic\Crawler\CrawlUrlProvider\CrawlUrlProviderCollection $providers
  2. Staatic\WordPress\Publication\Publication $publication

staatic_transformers

Allows additional transformers to be added or existing transformers to be removed from the list of transformers executed during a publication.

Transformers are used to modify results while they are processed during a publication.

Arguments
  1. Staatic\Framework\Transformer\TransformerInterface[] $transformers
  2. Staatic\WordPress\Publication\Publication $publication

staatic_post_processors

Allows additional post-processors to be added or existing post-processors to be removed from the list of post-processors executed during a publication.

Post-processors are used to modify the build after the crawler process has finished crawling the site.

Arguments
  1. Staatic\Framework\PostProcessor\PostProcessorInterface[] $postProcessors
  2. Staatic\WordPress\Publication\Publication $publication

Registering new deployment methods

In order to register a new deployment method you will need to create a new class that implements Staatic\Framework\DeployStrategy\DeployStrategyInterface. This class can then be registered using the staatic_deployment_strategy hook described below.

staatic_deployment_strategy

Determines the active deployment method that is used during the publication process.

Arguments
  1. Staatic\Framework\DeployStrategyInterface $deployStrategy
  2. Staatic\WordPress\Publication\Publication $publication

staatic_deployment_strategy_supports_preview

Determines whether the active deployment method supports preview publications.

Arguments
  1. bool $supportsPreviewPublications

staatic_deployment_strategy_validate

Returns validation errors related to the the active deployment method that should prevent the publication process from starting.

Arguments
  1. string[] $errors
  2. Staatic\WordPress\Publication\Publication $publication

Registering new settings

In order to register a new setting to be displayed in the Staatic for WordPress plugin interface, you will need to create a class that implements Staatic\WordPress\Setting\SettingInterface and register it using the staatic_settings hook described below.

staatic_settings

Allows additional settings to be added or existing settings to be removed from the list of registered settings.

Arguments
  1. array<string,Staatic\WordPress\Setting\SettingInterface> $settings

staatic_setting_groups

Allows additional setting groups to be added or existing groups to be removed from the list of registered setting groups.

Arguments
  1. Staatic\WordPress\SettingGroup\SettingGroup[] $settingGroups