Add-ons

What is an add-on?

An add-on is an extension that enhances the logic of a plugin or theme, thereby extending its capabilities.

Theme add-on

A theme add-on allows you to override part of the theme templates. Add-ons are activated in alphabetical order.
If a php template file with the same name is found in multiple add-ons, the file from the first activated add-on (the one at the top of the theme add-ons list) will be used.

Add-ons are only visible in the add-ons list under the add-on they were created for. They can only be activated after the theme is activated. Unlike themes, multiple add-ons can be activated.
If the add-on is disabled, its add-ons are also disabled.

Theme add-ons are located in the /themes/ directory.
Let's look at the structure of the mandatory index.php file of a theme add-on:

<?php

class Theme_StartAddon1 extends ThemeAddon
{
    public function init()
    {
        parent::init();

        $this->setSettings(array(
            'theme_title'   => 'Add-on name',
            'theme_version' => '1.0.0', // Add-on version
            'extension_id'  => 't0be932932ee5f2ec040bcc7e91cc25d0176dc71', // unique add-on identifier
        ));

        // Base theme
        $this->setAddonFor('base');
        // Start theme (unique theme identifier)
        $this->setAddonFor('t062d9070171056ece3322974c559def61ca11ff');

        /**
         * Settings
         */
        $this->configSettings(array(
            // Add-on settings
        ));
    }

    protected function start()
    {
        
    }
}

Let's describe it in more detail:

  • The name of the theme add-on class always starts with the prefix Theme_, and the class itself inherits the base class ThemeAddon.
  • The init function specifies the add-on name, version, and declares additional settings. If there are settings with the same key name, the add-on settings override the original theme settings.
  • The setAddonFor method is used to indicate the theme to which the add-on belongs. Multiple calls to this method can be made, and the add-on can be associated with multiple themes (as shown in the example).
  • The rest of the add-on code should be placed in the start function and other functions of this class. Additional php files with functions should also be included in the start function, or directly before they are used.

If you need to make changes or modifications to the templates of an existing add-on, you can do so using the customization mechanism.

In all other respects, a theme add-on has the same capabilities as a theme.

Plugin Add-ons

The function and operation of a plugin add-on is identical to that of theme add-ons.
The index.php file has the same structure as a regular plugin. Add-ons are located in the /plugins/ directory.

To indicate the association with a plugin, the setAddonFor method is called, specifying the identifier of the original plugin. It is also possible to associate it with multiple plugins and/or themes.