#60595 closed defect (bug) (duplicate)
The sanitize_callback is called twice when the option is saved the first time in the database
| Reported by: | inf3rno | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Plugins | Version: | 6.4.3 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: | administration |
Description
I have an array option containing many booleans coming from checkboxes.
Initially the database options table does not contain this option and the booleans are coming from its defaults array.
When I check a checkbox and save the option the first time on my admin page, then sanitize_callback is called with {"x":"on"} input the first time and the output is {"a":false,"b":false, ..., "x":true}. After that the sanitize_callback is called a second time with the input {"a":false,"b":false, ..., "x":true} and because isset(false) is true I got {"a":true,"b":true, ..., "x":true} as the output, which is saved to the database.
When I change a value again on my admin page the sanitize_callback is called only once with {"a":"on", "x":"on"}, which is the normal behavior.
I am sure this is a bug because the sanitize_callback is called with already sanitized data the second time.
Others found this too two years ago, but apparently nobody reported it. https://stackoverflow.com/questions/71974444/wordpress-register-setting-sanitize-callback-runs-twice-on-initial-save
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Duplicate of #21989.