WordPress customizer change sanitize_callback for setting doesn’t have any effect

My problem:
I have replaced the color input in the customizer with an input that supports the alpha channel. The sanitization function from WordPress is only for hex colors but I get rgba() colors. I wrote a sanitization function that works perfectly for any new control I add to the customizer but if I replace an existing one and change the sanitize_callback parameter of the corresponding setting to my own function ($wp_customize->get_setting("background_color")->sanitize_callback = "slug_sanitize_color";) WordPress still uses its standard sanitize_hex_color. The output of var_dump($wp_customize->get_setting("background_color")->sanitize_callback); is string(19) "slug_sanitize_color" so I guess it should work. If more code is needed I can provide it.
My question:
What do I have to do to make WordPress use my sanitization function for a preexisting control instead of the one WordPress ships with?

Read more here: WordPress customizer change sanitize_callback for setting doesn’t have any effect

Leave a Reply

Your email address will not be published. Required fields are marked *