WPBones icon indicating copy to clipboard operation
WPBones copied to clipboard

Allow null as option default value

Open ManuDoni opened this issue 2 years ago • 3 comments

Currently, if you set an option default value to null in your config/option.php file, every time you activate the plugin the value of that option is deleted, whatever the current value is.

ManuDoni avatar Jun 29 '23 13:06 ManuDoni

@ManuDoni currently you can delete an option using

$plugin->options->set( 'General.option_1', null );

So this request wouldn't work. Could you describe in what scenario it would be useful to receive a null option?

gfazioli avatar Mar 25 '24 14:03 gfazioli

My use case was this: I had an option that contained an oauth2 token. In my config I had something like this:

[
    "ms-graph-api": [
        "client_id": "",
        "client_secret": "",
        "token": null,
    ]
]

The token, when present, is an array that contains the expiry, the access token and the refresh token. With the current version the token is deleted every time I deactivate the plugin because of the null default value.

I don't mind if you want to delete this PR, I don't need this anymore because we abandoned the project we built on top of this nice little framework.

I believe this PR would be a breaking change but maybe the fact that a null default value has this side effect should be in the documentation.

ManuDoni avatar Mar 25 '24 23:03 ManuDoni

@ManuDoni To participate more actively in discussions and stay updated on proposals and latest releases, I would be pleased if you joined the WP Bones community on Discord.

gfazioli avatar May 02 '24 11:05 gfazioli