# 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="/pages/Khfo6jYaOwlk1U0PWYnW" %}
[Execute custom script on specific AcyMailing actions](/developers/making-a-custom-add-on/execute-custom-script-on-specific-acymailing-actions.md)
{% endcontent-ref %}

{% content-ref url="/pages/JLIo6jjwVnleaHfej30l" %}
[Insert a dynamic text in an email for Joomla](/developers/making-a-custom-add-on/insert-a-dynamic-text-in-an-email-for-joomla.md)
{% endcontent-ref %}

{% content-ref url="/pages/IxyzhiqSd4CKIapfuiwB" %}
[Insert a custom block in an email for Joomla](/developers/making-a-custom-add-on/insert-a-custom-block-in-an-email-for-joomla.md)
{% endcontent-ref %}

{% content-ref url="/pages/KIbtiESxfZWeOmXdf5BV" %}
[Insert a dynamic text in an email for WordPress](/developers/making-a-custom-add-on/insert-a-dynamic-text-in-an-email-for-wordpress.md)
{% endcontent-ref %}

{% content-ref url="/pages/k558IDPWabUmTCJwUheA" %}
[Insert a custom block in an email for WordPress](/developers/making-a-custom-add-on/insert-a-custom-block-in-an-email-for-wordpress.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acymailing.com/developers/making-a-custom-add-on.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
