radiate-framework / framework

A WordPress plugin and theme framework
https://radiate-framework.github.io/
MIT License
4 stars 0 forks source link

Option set/delete multiple #122

Closed BenRutlandWeb closed 3 years ago

BenRutlandWeb commented 3 years ago

Is your feature request related to a problem? Please describe. When activating/deactivating a plugin, it would be great to set/delete multiple global options.

Describe the solution you'd like Additional methods on the Option facade to add and delete (and maybe get?) options.

Option::addMany([
  'option_1' => 1,
  'option_2' => 2,
]);

Option::deleteMany(['option_1', 'option_2']);

[$option_1, $option_2] = Option::getMany(['option_1', 'option_2']);

Describe alternatives you've considered Manually looping over options.

BenRutlandWeb commented 3 years ago

AddMany and deleteMany are nice simple methods to loop internally, getMany needs a bit more thought to cater for defaults. Perhaps:

[$option_one, $option_2] = Option::getMany([
    'option_1' => 'default',
    'option_2' => 'default',
]);

...with 'default' being the fallback if the value isn't found in the options table. I remember seeing this pattern somewhere in Laravel.