• Hi!

    We have noticed some strange behavior with Redis Object Cache. If the cache is enabled we can not update checkboxes to a false state in our wp_options database table. You can run into the issue with the following example:

    add_action('customize_register', function ($wp_customize) {
        add_option('testc_checkbox_setting_id', true);
        $wp_customize->add_setting('testc_checkbox_setting_id', [
            'type' => 'option',
            'sanitize_callback' => function ($checked) {
                return isset($checked) && true == $checked ? true : false;
            }
        ]);
    
        $wp_customize->add_control('testc_checkbox_setting_id', [
            'type' => 'checkbox',
            'section' => 'static_front_page',
            'label' => __('Custom Checkbox'),
            'description' => __('This is a custom checkbox input.'),
            'settings' => 'testc_checkbox_setting_id'
        ]);
    });

    This code simply registers a new checkbox in Design > Customizer > Homepage Settings > “CUSTOM CHECKBOX”. If you try now to deactivate the checkbox (state: not checked), the value never gets updated in the database.

    If we deactivate the Redis object cache, all is working fine.

    Status: Connected
    Client: PhpRedis (v5.2.2)
    Drop-in: Valid
    Disabled: No
    Filesystem: Working
    Ping: 1
    Errors: []
    PhpRedis: 5.2.2
    Predis: Not loaded
    Credis: Not loaded
    PHP Version: 7.4.6
    Plugin Version: 2.0.8
    Redis Version: 6.0.3
    Multisite: No
    Global Prefix: "wp_"
    Blog Prefix: "wp_"
    WP_REDIS_HOST: "redis"
    WP_REDIS_MAXTTL: "14400"
    WP_REDIS_PREFIX: "wp.io_obj:"
    WP_CACHE_KEY_SALT: "wp.io_obj:"
    Global Groups: [
        "blog-details",
        "blog-id-cache",
        "blog-lookup",
        "global-posts",
        "networks",
        "rss",
        "sites",
        "site-details",
        "site-lookup",
        "site-options",
        "site-transient",
        "users",
        "useremail",
        "userlogins",
        "usermeta",
        "user_meta",
        "userslugs",
        "blog_meta"
    ]
    Ignored Groups: [
        "counts",
        "plugins",
        "themes",
        "mailster",
        "WPML_ST_Package_Factory"
    ]
    Unflushable Groups: []
    Drop-ins: [
        "maintenance.php v by ",
        "Redis Object Cache Drop-In v2.0.8 by Till Krüss"
    ]

    Regards,
    Matthew 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Till Krüss

    (@tillkruess)

    I never got an email notification for this.

    This is weird, have you tried to re-product this on a clean WP installation?

    Thread Starter Matthias Günter

    (@mguenter)

    Hi @tillkruess !

    Yeah, I tried this on a clean installation.

    Just give the example code above a chance and you will encounter this issue.

    Regards,
    Matthew 🙂

    Plugin Author Till Krüss

    (@tillkruess)

    If you remove add_option('testc_checkbox_setting_id', true); that code snippet works fine for me on 2.0.10. Saves the state of the checkbox 👍🏻

    Thread Starter Matthias Günter

    (@mguenter)

    Hi again!

    Unfortunately I can not remove the add_option as it is neede for autoload functionality of wp_options table itself. Can you still save the state “unchecked” without add_option functionality?

    Regards,
    Matthew 🙂

    Plugin Author Till Krüss

    (@tillkruess)

    In that case, it’s not working because your code is broken 👍🏻

    Thread Starter Matthias Günter

    (@mguenter)

    Hi again!

    How can the code be broken? add_option only adds the option to database when it is not already written.

    Regards,
    Matthew 🙂

    Plugin Author Till Krüss

    (@tillkruess)

    You should not set options in your customize_register action.

    If you want to debug why it’s not working with Redis, try using redis-cli monitor and see what happens when add_option() is called.

    Thread Starter Matthias Günter

    (@mguenter)

    Hi again!

    I really thought I was technically good at WordPress, but you never stop learning. This really solves the problem. Thanks for the great tip and have a nice weekend! 🙂

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Does not update `false` values’ is closed to new replies.