Plugin Support
qtwrk
(@qtwrk)
<?php
require('./wp-load.php');
update_option('test_option', 'test_value');
echo '<pre>' . var_dump(get_option('test_option')) . '</pre>';
echo "update to empty<br><br>";
update_option('test_option', '');
echo '<pre>' . var_dump(get_option('test_option')) . '</pre>';
above test code returns
string(10) "test_value"
update to empty
string(0) ""
seems alright on me
please explain a bit what exactly did you do ?
a sample code would be great help though.
-
This reply was modified 11 months, 1 week ago by
qtwrk.
-
This reply was modified 11 months, 1 week ago by
qtwrk.
Okay I found what is going “wrong”:
In the plugin, I have a sanitize routine that returned false when the option is empty. In normal operations, without Object cache, this is stored in the DB as an empty option. Then fetched again, it shows an empty result (not false) but apparently when added to the object cache, this conversion from false to empty does not take place.
So for testing purposes, try:
<?php
require('./wp-load.php');
update_option( 'test_option', 'test_value' );
update_option( 'test_option', false );
var_dump( get_option( 'test_option' ) );
I have not tested this exact code sample but I suspect that with the object cache active, the dumped variable shows bool(false), while without object cache or after a purge it will be string(0) "".
Plugin Support
qtwrk
(@qtwrk)
the one you provided , show bool false on me , with and without object cache
After update_option( 'test_option', false ) the option is stored in the database as an empty value, correct? Then get_option( 'test_option' ) should not be returning false but ''. It should only return false if the option is not found in the database…
The only difference between the test code and my plugin is that the option’s autoload is set to auto-on (via a wp_default_autoload_value filter) … Please try with the autoload flag:
update_option( 'test_option', 'test_value', true );
update_option( 'test_option', false, true );
var_dump( get_option( 'test_option' ) );
I tested this and it does show different results with and without the object cache. At least on my dev site.
Hope this helps π
Plugin Support
qtwrk
(@qtwrk)
with your latest code, I tested again , on a clean, new installed WP (no LiteSpeed plugin installed) , it still return bool false … π§
That is weird. Is the option actually in the DB?
Plugin Support
qtwrk
(@qtwrk)
yes, I looked in DB, it’s there and empty , have you tried on a clean wp ? what does it show to you ?
Interesting…
Try this:
update_option( 'test_option_1', 'test_value' );
update_option( 'test_option_1', false );
var_dump( get_option( 'test_option_1' ) );
update_option( 'test_option_2', 'test_value', true );
update_option( 'test_option_2', false, true );
var_dump( get_option( 'test_option_2' ) );
update_option( 'test_option_3', 'test_value', false );
update_option( 'test_option_3', false, false );
var_dump( get_option( 'test_option_3' ) );
My result are:
bool(false) bool(false) string(0) ""
So I would guess the inconsistency is within WordPress itself, not the object caching?
Plugin Support
qtwrk
(@qtwrk)
bool(false) bool(false) string(0) ""
okay …. this set of code gives me this result , with and without object cache …
Even more interesting:
var_dump( get_option( 'test_option_1' ) );
update_option( 'test_option_1', 'test_value' );
update_option( 'test_option_1', false );
var_dump( get_option( 'test_option_1' ) );
var_dump( get_option( 'test_option_2' ) );
update_option( 'test_option_2', 'test_value', true );
update_option( 'test_option_2', false, true );
var_dump( get_option( 'test_option_2' ) );
var_dump( get_option( 'test_option_3' ) );
update_option( 'test_option_3', 'test_value', false );
update_option( 'test_option_3', false, false );
var_dump( get_option( 'test_option_3' ) );
Gives:
string(0) "" bool(false) string(0) "" bool(false) string(0) "" string(0) ""
So it’s in the WP core options cache where the inconsistency occurs…
Anyway, not an object cache issue. Thanks for looking into this with me π
Plugin Support
qtwrk
(@qtwrk)
update_option( 'test_option_1', 'test_value' );
update_option( 'test_option_1', false );
var_dump( get_option( 'test_option_1' ) );
if I do this , it gives bool false , if I do
#update_option( 'test_option_1', 'test_value' ); # no update on this one
update_option( 'test_option_1', false );
var_dump( get_option( 'test_option_1' ) );
then it gives string “”
it just looks like it doesn’t like the way that you update the same option multiple times in same request ?
-
This reply was modified 11 months, 1 week ago by
qtwrk.
it just looks like it doesnβt like the way that you update the same option in same request ?
Indeed. See my answer just before where the code starts with getting the option from the DB and then updating with different dump…
I guess that with the Object cache on, this “odd” behavior is made persistent across requests. Not the object caches fault, just that it made it apparent (I’m not updating the option twice in one request but only after Save on the options page)