[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 12:30:09 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: close | Focuses:
--------------------------+------------------------------
Changes (by alexvorn2):
* status: closed => reopened
* resolution: invalid =>
Comment:
Replying to [comment:2 subrataemfluence]:
> According to the structure as of now the datatype the `option_name`
column in `wp_options` is of string type (`varchar(191)`).
>
> The reason it does not add a record with `update_option('aaa2345454',
false)` is you are passing a Boolean value.
>
> To add / update a record with value `true` or `false` you either need to
pass it directly as string like
>
> {{{
> update_option('aaa2345454', 'false');
> }}}
>
> or in case you are grabbing this value from somewhere else which is a
Boolean then you need to create a string alternative for your value before
you actually send it:
>
> {{{
> $value = true; //hard coding the $value here. You may be grabbing it
from somewhere else.
> $converted_value = ($value) ? 'true' : 'false';
> update_option('aaa2345454', $converted_value)
> }}}
>
> The above would add / update the value in `wp_options` table with a
value either `true` or `false` in `option_value` column. However, the
value would not insert as a real Boolean type.
I want to add a Boolean false value, not STRING 'false' value, these are 2
different things.
Why {{{update_option( 'aaa2345', true )}}} works and {{{update_option(
'aaa2346', false )}}} does not?
I think you did not understand the issue here. I will reopen this, why
close so fast? Just a close keyword is enough, maybe someone has a
different opinion.
Even if {{{update_option( 'aaa2346', false )}}} does not work it should at
least insert a new row into the database.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40007#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list