# Making a custom add-on

AcyMailing has a lot of features, but it isn't integrated with every other extension. You may want to create your own custom add-on to:

* insert dynamic texts in your emails (the current month, an event name, etc…)
* insert user information in your emails (a custom field, a personal information, etc…)
* automatically insert content built in other extensions (products, events, articles, etc…)
* execute a script when a specific action is performed in AcyMailing (when a new user subscribes, when a user is imported, etc…)

### Creating my custom add-on

{% tabs %}
{% tab title="Joomla" %}
First create the main folder for your add-on. It must be in lowercase with only letters: administrator/components/com\_acym/dynamics/**exampleaddon**/

Inside this folder, create the file **plugin.php** like this one:

{% code lineNumbers="true" %}

```php
<?php

use AcyMailing\Core\AcymPlugin;

class plgAcymExampleaddon extends AcymPlugin
{
}

```

{% endcode %}

The class name MUST always be "**plgAcym**" followed by the folder name of your add-on, with a capital letter at the beginning.

The content of the class will be described in the next sections.
{% endtab %}

{% tab title="WordPress" %}
First create the main folder for your WordPress plugin, for example wp-content/plugins/**custom-add-on-for-acymailing**/

In this folder, create the file **custom-add-on-for-acymailing.php** with the following content:

{% code lineNumbers="true" %}

```php
<?php
/*
 * Plugin Name: Custom add-on for AcyMailing
 * Description: Insert dynamic texts inside sent emails
 * Version: 1.0
 * Requires Plugins: acymailing
*/

use AcyMailing\Classes\PluginClass;

class myCustomAddonForAcyMailing
{
    const INTEGRATION_PLUGIN_NAME = 'plgAcymExampleaddon';

    private string $integrationName;

    public function __construct()
    {
        register_deactivation_hook(__FILE__, [$this, 'disable']);
        register_uninstall_hook(__FILE__, [$this, 'uninstall']);
        add_action('acym_load_installed_integrations', [$this, 'register'], 10, 1);

        $this->integrationName = strtolower(substr(self::INTEGRATION_PLUGIN_NAME, 7));
    }

    public function disable(): void
    {
        if (!$this->loadAcyMailingLibrary()) {
            return;
        }

        $pluginClass = new PluginClass();
        $pluginClass->disable($this->integrationName);
    }

    public function uninstall(): void
    {
        if (!$this->loadAcyMailingLibrary()) {
            return;
        }

        $pluginClass = new PluginClass();
        $pluginClass->deleteByFolderName($this->integrationName);
    }

    public function register(array &$integrations): void
    {
        $integrations[] = [
            'path' => __DIR__,
            'className' => self::INTEGRATION_PLUGIN_NAME,
        ];
    }

    private function loadAcyMailingLibrary(): bool
    {
        $ds = DIRECTORY_SEPARATOR;
        $vendorFolder = dirname(__DIR__).$ds.'acymailing'.$ds.'vendor';
        $initFile = dirname(__DIR__).$ds.'acymailing'.$ds.'back'.$ds.'Core'.$ds.'init.php';

        return file_exists($vendorFolder) && include_once $initFile;
    }
}

new myCustomAddonForAcyMailing();

```

{% endcode %}

You will need to modify:

* your plugin name on line 3, that will be shown on your plugins listing
* lines 11 and 64 to name the class however you like (make it something unique to avoid conflicts)
* line 13 where the value MUST **start with "plgAcym"** and be followed by a capital letter then lowercase letters.\
  ⚠️ <mark style="color:red;">Remember this value as it will be used as the class name of our add-on</mark> ⚠️

Create the file **plugin.php** in the same folder.

{% code lineNumbers="true" %}

```php
<?php

use AcyMailing\Libraries\acymPlugin;

class plgAcymExampleaddon extends acymPlugin
{
}

```

{% endcode %}

Notice that the class name MUST be the same you set in the previous file on line 13.\
The content of the class will be described in the next sections.
{% endtab %}
{% endtabs %}

### Adding features to your custom add-on

Once your custom add-on's base files are created, you can add methods in the **plugin.php** file to customise AcyMailing features.

{% content-ref url="making-a-custom-add-on/execute-custom-script-on-specific-acymailing-actions" %}
[execute-custom-script-on-specific-acymailing-actions](https://docs.acymailing.com/developers/making-a-custom-add-on/execute-custom-script-on-specific-acymailing-actions)
{% endcontent-ref %}

{% content-ref url="making-a-custom-add-on/insert-a-dynamic-text-in-an-email-for-joomla" %}
[insert-a-dynamic-text-in-an-email-for-joomla](https://docs.acymailing.com/developers/making-a-custom-add-on/insert-a-dynamic-text-in-an-email-for-joomla)
{% endcontent-ref %}

{% content-ref url="making-a-custom-add-on/insert-a-custom-block-in-an-email-for-joomla" %}
[insert-a-custom-block-in-an-email-for-joomla](https://docs.acymailing.com/developers/making-a-custom-add-on/insert-a-custom-block-in-an-email-for-joomla)
{% endcontent-ref %}

{% content-ref url="making-a-custom-add-on/insert-a-dynamic-text-in-an-email-for-wordpress" %}
[insert-a-dynamic-text-in-an-email-for-wordpress](https://docs.acymailing.com/developers/making-a-custom-add-on/insert-a-dynamic-text-in-an-email-for-wordpress)
{% endcontent-ref %}

{% content-ref url="making-a-custom-add-on/insert-a-custom-block-in-an-email-for-wordpress" %}
[insert-a-custom-block-in-an-email-for-wordpress](https://docs.acymailing.com/developers/making-a-custom-add-on/insert-a-custom-block-in-an-email-for-wordpress)
{% endcontent-ref %}
