[wp-trac] [WordPress Trac] #40007: update_option function does not work if the $value argument is false on a nonexistent option
WordPress Trac
noreply at wordpress.org
Thu Mar 2 15:03:56 UTC 2017
#40007: update_option function does not work if the $value argument is false on a
nonexistent option
--------------------------+------------------------------
Reporter: alexvorn2 | Owner:
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by subrataemfluence):
Further inspecting the core function `update_action` reveals something
strange!
The value `false` is actually being treated as an empty string, but `true`
is not! So when I am passing `false` for a key which I know does not exist
there yet, `get_option` returns an empty string (`$old_value = get_option(
$option );`), which when being compared in the following snippet:
{{{
if ( $value === $old_value ) return false;
}}}
always returning false as both `$value` and `$old_value` are nothing but
'''empty strings'''!
This is the reason `update_option('_option_key_index', false)`, never adds
a record in the database. But if I pass
`update_option('_option_key_index', 0)` it does.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40007#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list