Can I save plugin setting as JSON or serialized array?

Re: Can I save plugin setting as JSON or serialized array?

by Darko Miletić -
Number of replies: 1
Yes, you can do whatever is needed in terms of the value, but you need to ensure that proper encoding/decoding is performed wherever is needed.

What people usually use is serialized object encoded in base64 format. Example:
$value = base64_encode(serialize($data));
set_config('configname', $value, 'mypluginname');
data can be simple array or object, as you please. That upon reading you do decoding:
$value = get_config('configname', 'mypluginname');
if ($value !== false) {
$data = unserialize(base64_decode($value));
// Do something.
}


In reply to Darko Miletić

Re: Can I save plugin setting as JSON or serialized array?

by Juho Jaakkola -

Thanks, but there's still the question of how and where to implement the settings page and the code that processes multiple setting inputs into a single setting value.

In what file would you place your code example?