[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 07:08:51 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:  closed
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:  invalid
 Keywords:  close         |     Focuses:
--------------------------+------------------------------
Changes (by subrataemfluence):

 * keywords:   => close
 * status:  new => closed
 * resolution:   => invalid


Comment:

 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40007#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list