# PluginsSettingsEvent events

> 2 FeatherPanel plugin events on PluginsSettingsEvent (2 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/plugins-settings/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions.

## Setup

Import `PluginsSettingsEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\PluginsSettingsEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(PluginsSettingsEvent::onPluginSettingDelete(), function ($identifier, $key): void {
            App::getInstance(true)->getLogger()->info('[myplugin] plugins:settings:delete ' . json_encode(['identifier' => $identifier]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `PluginsSettingsEvent::onPluginSettingDelete()`

- Name: `plugins:settings:delete`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/PluginsSettingsEvent.php#L29)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `identifier` | `$identifier` | `string` |
| 2 | `key` | `$key` | not declared |

When it fires (1 site)

-   [`PluginsController::removeSettings`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PluginsController.php#L456)[`POST /api/admin/plugins/{identifier}/settings/remove`](https://featherpanel.com/docs/api/reference/admin/plugins/#post-admin-plugins-identifier-settings-remove)

```php
$event->on(PluginsSettingsEvent::onPluginSettingDelete(), function ($identifier, $key): void {
    App::getInstance(true)->getLogger()->info('[myplugin] plugins:settings:delete ' . json_encode(['identifier' => $identifier]));
});
```

## `PluginsSettingsEvent::onPluginSettingUpdate()`

- Name: `plugins:settings:update`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/PluginsSettingsEvent.php#L24)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `identifier` | `$identifier` | `string` |
| 2 | `key` | `$key` | not declared |
| 3 | `value` | `$value` | `bool` |

When it fires (1 site)

-   [`PluginsController::setSettings`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PluginsController.php#L370)[`POST /api/admin/plugins/{identifier}/settings/set`](https://featherpanel.com/docs/api/reference/admin/plugins/#post-admin-plugins-identifier-settings-set)

```php
$event->on(PluginsSettingsEvent::onPluginSettingUpdate(), function ($identifier, $key, $value): void {
    App::getInstance(true)->getLogger()->info('[myplugin] plugins:settings:update ' . json_encode(['identifier' => $identifier, 'value' => $value]));
});
```
