[wp-trac] [WordPress Trac] #31061: Accept FALSE as valid value from "pre_option_" hook
WordPress Trac
noreply at wordpress.org
Tue Jan 27 15:07:00 UTC 2015
#31061: Accept FALSE as valid value from "pre_option_" hook
--------------------------------+------------------------------
Reporter: martin.krcho | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version: 4.1
Severity: normal | Resolution:
Keywords: close | Focuses: performance
--------------------------------+------------------------------
Comment (by boonebgorges):
> how would I go about caching options values that are not autoloaded and
can return false as a valid option value? Is there anything I am missing
or is it simply not possible using current latest WordPress version?
It's not possible to do it in a reliable way. The best I can suggest is
that you cache an empty string (or even a string 'false'), and convert it
to `false` as necessary where it's being consumed. I understand that this
is pretty inconvenient and ugly. But our options system is designed around
a MySQL key-value store, and boolean `false` is translated to an empty
string when it's stored in the database like this. The fact that you can
put a boolean directly into the persistent cache without having it
converted to a string is sort of an undocumented feature.
Long term, we might consider augmenting the options/meta schema so as to
store the data type as well: a column 'type' that stores 'int', 'bool',
etc. Then functions like `get_option()` etc would have a `$strict`
parameter, and our cache implementation would be type-sensitive.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31061#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list