Quite often an extension needs a storage to keep its data - for example, user settings or secret keys. To access the Plesk key-value storage, use the pm_Settings interface. Keys and values are stored in the context of an extension.
If you need to assign a variable, use pm_Settings::set. For example:
Now you can retrieve the value of this variable by pm_Settings::get. For example:
To obtain access to them in some places of code, initialize the context first:
It is mandatory to initialize the context in the following places in code:
- Scheduled tasks.
- Post- and Pre- installation scripts.
- Event handlers.
Starting with Plesk 12.5, it is possible to clear the extension settings using the
pm_Settings::clean method. You can use it to add a "Reset to default" button to the UI of your extension.