pantheon-systems / wp-redis

WordPress Object Cache using Redis.
https://wordpress.org/plugins/wp-redis/
GNU General Public License v2.0
226 stars 68 forks source link

get_option returns wrong value #364

Closed christofervas closed 1 year ago

christofervas commented 1 year ago

Hello,

I use the plugin in a multisite installation. When the plugin is network activated and the object-cache.php file is in place I get the value as bool(true) from get_option() in a subsite instead of string(1) "1" as explained here: https://developer.wordpress.org/reference/functions/get_option/#description

This create us issues with popular plugins such as Gravity Forms that make the following comparison of the returned value:

$returned_value === "1"

jazzsequence commented 1 year ago

@christofervas get_option is a WordPress core function that takes a parameter (the option value). The documentation linked indicates that the return value of the get_option can be anything as it's context-specific (see https://developer.wordpress.org/reference/functions/get_option/#return). Are you saying that when this plugin is installed get_option() (no option name passed) returns true when it should return "1" or is there a specific option related to the WP Redis plugin that is returning a value that is unexpected (and if so, what option name are you requesting)? Or are you saying that all options that are true/false are returning boolean values when they should return strings when the plugin is installed (but not when it is not)?

christofervas commented 1 year ago

I now use another plugin. However, as I remember the issue was that we stored the value "1" as a string but when the plugin was activated we got a boolean value bool(true).

jazzsequence commented 1 year ago

Thanks for the followup @christofervas

jazzsequence commented 1 year ago

Tracking internally as BUGS-5416

jazzsequence commented 1 year ago

I'm unable to reproduce this issue.

To attempt to reproduce, I installed WP Redis and then created a new mu-plugin that included an options page. On the options page, I had a radio button that included options for true, false, '1', '0', 'true', 'false', 1,0. I then added a pre_update_option_{option-name} hook that explicitly saved whatever was stored in my option as a boolean value in a different option.

WordPress did not distinguish between true, false, 1, 0, '1' or '0'. 'true' and 'false' were correctly interpreted as strings and therefore true when cast as boolean values no matter which was selected.

Whether the plugin was active or not, the results I got always cast a truthy value as '1' and a falsey value as '' (when I explicitly converted to boolean) or '0' (when I pulled from the stored option).

Tested on PHP versions 7.4, 8.0 and 8.2.

If anyone sees this and has the same issue, please update this report with specific information about your environment, options you are saving, plugins you have installed, etc. so we can dig further into this. In the meantime, I'm closing this ticket.