[wp-trac] [WordPress Trac] #32848: Null values for Update Options does not reset in $all_options

WordPress Trac noreply at wordpress.org
Fri Jul 26 05:43:46 UTC 2024


#32848: Null values for Update Options does not reset in $all_options
--------------------------------------+--------------------------
 Reporter:  MikeNGarrett              |       Owner:  pbearne
     Type:  defect (bug)              |      Status:  accepted
 Priority:  normal                    |   Milestone:  6.7
Component:  Cache API                 |     Version:  4.2.2
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  performance
--------------------------------------+--------------------------

Comment (by peterwilsoncc):

 Related #22192.

 This appears to be due to how `add_option()` caches data compared to how
 it is stored in the database. When the data is originally cached it uses
 the data type as passed to the function. When stored in the database, the
 data is type cast to a string.

 Without a persistent cache, subsequent requests to load alloptions will
 result in `isset() === true` as the value will be returned as an empty
 string. To demonstrate via WP CLI:

 {{{

 vagrant at wp-dev:/vagrant$ wp shell
 wp> add_option( '6766-testing', null );
 =>
 bool(true)
 wp> wp_load_alloptions()['6766-testing']
 =>
 NULL
 wp> isset( wp_load_alloptions()['6766-testing'] )
 =>
 bool(false)
 wp> exit


 vagrant at wp-dev:/vagrant$ wp shell
 wp> wp_load_alloptions()['6766-testing']
 =>
 string(0) ""
 wp> isset( wp_load_alloptions()['6766-testing'] )
 =>
 bool(true)
 wp> exit
 }}}

 I suspect the best option might be to ensure that options are cached in
 the same form that they are stored (ie, as a string). This would ensure
 that the behavior of `get_option()` doesn't randomly change depending on
 whether the cache is populated or unpopulated.

 Although some work along these lines in #22192 proved to be risky and was
 ultimately reverted.

 (Mike and Paul: I know you're probably aware of the cause but best to
 spell it out.)

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


More information about the wp-trac mailing list