Make WordPress Core

Opened 5 years ago

Last modified 4 weeks ago

#15335 reopened defect (bug)

register_setting() filter for sanitization callback needs to indicate 2 arguments accepted

Reported by: lumination Owned by: markjaquith
Milestone: Future Release Priority: normal
Severity: normal Version: 3.1
Component: Options, Meta APIs Keywords: needs-patch early
Focuses: administration Cc:


register_setting() adds the function for sanitization of the option with the following line (wp-admin/includes/plugin.php):

add_filter( "sanitize_option_{$option_name}", $sanitize_callback );

For users wanting to declare a function for option sanitization, use of the option name within the function is sometimes desired, and is provided for in the filter application inside the sanitize_option() declaration as such (wp-includes/formatting.php):

$value = apply_filters("sanitize_option_{$option}", $value, $option);

With the filter always being applied with the option name as the second argument, I see no reason not to propose that the add_filter() call in register_setting() include "2" as the number of accepted arguments, allowing the option name to be passed.

Attachments (3)

15335.diff (486 bytes) - added by solarissmoke 5 years ago.
15335.2.diff (479 bytes) - added by solarissmoke 5 years ago.
15335_params.diff (1.1 KB) - added by ejdanderson 4 years ago.
Filter args as optional parameters.

Download all attachments as: .zip

Change History (20)

#1 @goto10
5 years ago

  • Cc goto10 added

#2 @lumination
5 years ago

  • Component changed from General to Plugins

#3 @nacin
5 years ago

  • Keywords needs-patch added; register_setting removed
  • Milestone changed from Awaiting Review to Future Release

It's not difficult to derive this from current_filter(). Seems sane though. Future pending patch.

5 years ago

#4 @solarissmoke
5 years ago

  • Keywords has-patch added; needs-patch removed

#5 @nacin
5 years ago

This is an add_filter() call, not apply_filters(). So probably needs to be 10, 2.

5 years ago

#6 @solarissmoke
5 years ago

Oops, yeah, bit slow this morning :)

4 years ago

Filter args as optional parameters.

#7 @markjaquith
4 years ago

  • Keywords early added
  • Owner set to markjaquith
  • Status changed from new to accepted

This is a really lame omission. You should be able to have a generic save handler that does a switch on the option name and does your sanitization magic. 3.3-early, please.

+1 for solarissmoke's patch: 15335.2.diff

Last edited 4 years ago by markjaquith (previous) (diff)

#8 @SergeyBiryukov
4 years ago

  • Milestone changed from Future Release to 3.3

#9 @markjaquith
4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In [18887]:

Pass both parameters to the sanitize_option_FOO callback set in register_setting(). props lumination. fixes #15335

#10 @duck_
4 years ago

  • Milestone changed from 3.3 to Future Release
  • Resolution fixed deleted
  • Status changed from closed to reopened

[18951] reverted [18887], see #18914.

Need to deal with back compat when using intval, for example, as a callback. See also #14671.

#11 @toscho
3 years ago

  • Cc info@… added

#12 @nacin
2 years ago

#26084 was marked as a duplicate.

#13 @nacin
22 months ago

  • Component changed from Plugins to Admin APIs
  • Focuses administration added

#14 @nacin
22 months ago

  • Component changed from Admin APIs to Plugins

Sorry for the noise.

#15 @SergeyBiryukov
16 months ago

  • Component changed from Plugins to Options, Meta APIs

#16 @SergeyBiryukov
16 months ago

#29193 was marked as a duplicate.

#17 @chriscct7
4 weeks ago

  • Keywords needs-patch added; has-patch removed
Note: See TracTickets for help on using tickets.