Learn

Anatomy of an Add-On

Getting familiar with Statamic's add-on architecture.

An add-on is how you can extend the core functionality of Statamic. Rather than digging in and messing with core files, we’ve created a system where developers can easily build new features that are compatible with everyone’s Statamic installations. Add-ons can then be easily shared or sold to others to let them extend their Statamic installation.

Where WordPress has plugins and Drupal has modules, Statamic has add-ons.

The Many Faces of an Add-On

One add-on should be thought of as one new feature for your site. A “feature” can be something simple (such as a tag that returns the current time), or something large (such as Statamic’s form-builder, that builds, validates, and can process form-data). Although the complexity varies, each of those examples tackle one issue.

An add-on contains a number of aspects:

  • plugins
  • fieldtypes
  • hooks
  • tasks
  • modifier
  • API
  • core

Add-ons must have at least one of these aspects, otherwise it wouldn’t do anything, and each can use all of them. Each aspect accomplishes different missions.

  • plugins create tags for use within templates, this is the output aspect
  • fieldtypes create new ways to ask for data in the Control Panel, this is the input aspect
  • hooks connect add-on code with events that are happening with the system as they happen, this is the interconnectivity aspect
  • tasks allow you to run code at set intervals without people needing to visit the website, this is the background processing aspect
  • modifier lets you create your own variable modifier
  • API allows you to create an interface through which other add-ons can interact with your add-on (and vice-versa)
  • core allows you to create code that can be shared throughout your other aspects

By using combinations of these aspects in your add-ons, you can create some truly fascinating results. And remember, all of these aspects are simply PHP, so anything you can do with PHP is possible here. The sky is the limit.

This article was last updated on September 13th, 2016. Find an error? Please let us know!