WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#19315 closed defect (bug) (worksforme)

sanitize_option callback in register_setting()

Reported by: digitalnature Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2
Component: Validation Keywords:
Focuses: Cc:

Description

This is the user validation function you pass to register setting.

The problem is that if you're manually updating your option within this function, your option won't get updated because update_option() will run your callback on $newvalue, which changes it to the old option value. So it will do nothing because it would appear that both new and old values are identical.

I know there aren't many situations in which you would want to modify your option within that validation callback because that's what that callback should do in the first place, but they do exist :)

Change History (2)

comment:1 @sirzooro4 years ago

Try to return old value from sanitization callback instead of calling update_option() in it - should be enough.

comment:2 in reply to: ↑ description @nacin3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Replying to digitalnature:

I know there aren't many situations in which you would want to modify your option within that validation callback because that's what that callback should do in the first place, but they do exist :)

I don't think they do. Feel free to reopen this with an example, though.

Note: See TracTickets for help on using tickets.