[wp-trac] [WordPress Trac] #60595: The sanitize_callback is called twice when the option is saved the first time in the database
WordPress Trac
noreply at wordpress.org
Wed Feb 21 21:00:03 UTC 2024
#60595: The sanitize_callback is called twice when the option is saved the first
time in the database
----------------------------+-----------------------------
Reporter: inf3rno | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: 6.4.3
Severity: normal | Keywords:
Focuses: administration |
----------------------------+-----------------------------
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
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60595>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list