Make WordPress Core

Opened 10 months ago

Closed 10 months ago

Last modified 10 months ago

#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's profile inf3rno Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.4.3
Component: Plugins Keywords:
Focuses: administration Cc:

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

Change History (2)

#1 @inf3rno
10 months ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #21989.

#2 @swissspidy
10 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.