Topics

Plugin options

 Add options to your plugin to make it easier to set-up and use.

Options are defined in options section of Plugin/MyPlugin/Setup/plugin.json file, as in example below:

{
    "title": "My Plugin",
    "version": "1.00",
    "name": "MyPlugin",
    "description": "Lorem ipsum",
    "author": "Lorem ipsum",
    "options": [
      {
        "label": "Your email",
        "name": "yourEmail",
        "type": "Text",
        "default": ""
      },
      {
        "label": "Test mode",
        "name": "testMode",
        "type": "Checkbox",
        "default": 0
      },
      {
        "label": "Text color",
        "name": "textColor",
        "type": "Color",
        "default": "#000"
      },
      {
        "label": "Show my banner",
        "name": "showMyBanner",
        "type": "Select",
        "default": "yes",
        "values": ["no", "yes"]
      }
    ]
}

The following plugin option types are available: SelectTextTextareaColorRangeCheckbox, CheckboxesRichText, TextLang, TextareaLang (since 4.5.3). You can also add full class name of your custom form field type.

Each option accepts labelnamedefault, note, hint, validators parameters. 

Select option accepts additional values attribute.

Get option value

echo ipGetOption('MyPlugin.yourEmail');

Set option value

ipSetOption('MyPlugin.yourEmail', 'xxx@xxx.com');

Get a list of all website options

<?php 
    $options = new \Ip\Options();
    var_dump($options->getAllOptions());

See also

comments powered by Disqus