Table of Contents

Plugins parameters

Saving a parameter

First, you need to select the namespace associated to the parameters with the setNameSpace() function:

$core->blog->settings->setNameSpace('example');

Note:

The setNamespace() argument should only contain letters (without accents) or numbers.

Allowed characters are [a-zA-Z][a-zA-Z0-9]

Use the put() function to save a parameter. Its arguments are:

  1. the parameter name (a string containing alphanumeric characters or underscore _)
  2. its value
  3. its type (optional)
  4. its label (optional)
  5. wheter to overwrite the previous value or not (optional) (default value is true)
  6. where the parameter is global or not (optional) (default value is false)

Example with a string and a label

# we set the namespace
$core->blog->settings->setNameSpace('example');
 
# we save the parameter
$core->blog->settings->put('example',__('Hello World!'),'string','My label');
 
# we go back to the default namespace
$core->blog->settings->setNameSpace('system');

Parameters types

Saving a float:

$core->blog->settings->put('float',415618155.5181,'float');

Saving an integer:

$core->blog->settings->put('integer',21767426,'integer');

Saving a boolean:

$core->blog->settings->put('bool',true,'boolean');

Saving a string:

$core->blog->settings->put('string',__('Hello World!'),'string');

Warning:

To store a string containing more than one line, you should use the base64_encode() function when saving, and the base64_decode() when reading the parameter. This will prevent line break when editing the parameter with about:config.

Reading a parameter

A parameter is associated to the $core→blog→settings→parameter name variable, for example :

$string = $core->blog->settings->string;

Deleting a parameter

You have to use the drop() function :

$core->blog->settings->setNameSpace('example');
 
$core->blog->settings->drop('example');