[wp-trac] [WordPress Trac] #55942: Add a "value type" parameter to get_option() and get_metadata()
WordPress Trac
noreply at wordpress.org
Tue May 2 20:33:06 UTC 2023
#55942: Add a "value type" parameter to get_option() and get_metadata()
-------------------------------------------------+-------------------------
Reporter: azaozz | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.3
Component: Options, Meta APIs | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests needs- | Focuses:
testing | performance
-------------------------------------------------+-------------------------
Comment (by azaozz):
Replying to [comment:62 knutsp]:
> What will be the difference to writing...
No much difference, just a bit cleaner way to write it.
> If the saved type is still to be guessed...
It's not "to be guessed", rather it is to get a value with an expected
(strict) type.
> The main problem I have encountered is mostly determining the difference
between
> - `'my option'` not set/exists
> - `add_option( 'my_option', '' );`
> - `add_option( 'my_option', false );`
This touches on "best practices" when using the options API: "All options
should be set (and preferably autoloaded)". Currently when you do
`add_option( 'my_option', false );` and then `get_option( 'my_option' );`,
you get an empty string. That makes it possible to see if the option was
set to `false`, but I don't think this is a "good behavior". Ideally
whatever you save in the DB should come back the same. Returning strings
for boolean and integer values is a long-standing inconsistency. Adding
this param would make it easier to fix that.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/55942#comment:63>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list