Skip to content

Create Extension Guide

Extensions in Static Snap allow you to expand its capabilities by adding custom features or integrating with third-party services. These extensions are developed in PHP and designed to be modular, enabling easy customization of the static site generated by Static Snap. This guide will help you get started with creating your own extensions to tailor Static Snap to your specific needs.

Before creating an extension for Static Snap, make sure you have the following:

  • Proficiency in PHP: Since extensions for Static Snap are written in PHP, you should have a solid understanding of PHP programming and WordPress development.
  • WordPress Setup: Ensure that you have WordPress installed with Static Snap enabled to test your extension in a real-world environment.
  • Development Environment: A local development setup with tools like XAMPP, MAMP, or Local by Flywheel can make the development process smoother.

To create an extension for Static Snap, follow these steps:

  • Create a PHP File: Start by creating a PHP file for your extension, such as my-custom-extension.php, within the wp-content/plugins/static-snap-extensions/ directory.
  • Extend the Base Class: Your extension should extend the StaticSnap\Extension\Extension_Base class, which provides the necessary structure and hooks for integration.

Below is a basic template for creating a Static Snap extension in PHP:

<?php
/**
* Custom Search Extension for Static Snap
*
* @package StaticSnap
*/
namespace StaticSnap\CustomExtension;
use StaticSnap\Extension\Extension_Base;
use StaticSnap\Config\Options;
/**
* Class My_Custom_Extension
* A sample extension that adds search capabilities to the static site.
*/
class My_Custom_Extension extends Extension_Base {
/**
* Check if the extension is enabled
*
* @return bool
*/
public function is_enabled(): bool {
$options = Options::instance()->get('custom_extension.is_enabled', ['enabled' => false]);
return $options['enabled'];
}
/**
* Get the name of the extension
*
* @return string
*/
public function get_name(): string {
return 'my_custom_extension';
}
}

Static Snap provides a comprehensive set of actions and filters that you can utilize to customize its functionality. You can find the complete list of available actions in the Actions documentation, and a detailed overview of the filters in the Filters documentation.

  • Actions: Actions allow you to hook into various points of the plugin’s execution flow. For example, you can use the Actions::INIT action to execute custom code when the plugin initializes.

  • Filters: Filters enable you to modify data before it’s processed or displayed. For instance, you can use the Filters::POST_TYPES filter to add or modify post types in your extension.

Contribute

What’s on your mind?

Create GitHub Issue

Quickest way to alert our team of a problem.