Plugins > Variables
Beginning with WikyBlog 1.6, plugins can easily save and retrieve variables using the wbVariables class in the tool/Variables.php. Variables are stored in key => value pairs in the config_vars table. They are stored in relation to the plugin's namespace and can be retrieved and stored individually or as a whole.
wbVariables Class
| Method Name
| Return Value
| Description
|
| set($key,$value)
| Boolean
| Both strings, the $key must be less than 20 characters long, and the $value must be less than 255 characters long. An error will be thrown if either $key or $value are too long. Return true if successful and false otherwise.
|
| saveArray($array,[$deleteOthers])
| None
| This function will call wbVariables::set($key,$value) for each $key => $value pair in $array. You may set $deleteOthers to true to permanently remove keys that are not set in $array.
|
| get($key)
| String
| This function will return the $value that was stored for $key in the current namespace.
|
| getArray()
| Array
| This function will return an array of all the $key => $value pairs for the current namespace.
|
Example
<?php
includeFile('tool/Variables.php');
//Set foo
wbVariables::set('foo','bar');
//This will send a message of "bar" to the client
$value = wbVariables::get('foo');
message($value);
//Set bar
wbVariables::set('bar','foo');
//This will show both $key => $value pairs to the user
$array = wbVariables::getArray();
message(showArray($array));