WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 5 months 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: Plugins Keywords: has-patch early
Focuses: administration Cc:

Description

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 3 years ago.
15335.2.diff (479 bytes) - added by solarissmoke 3 years ago.
15335_params.diff (1.1 KB) - added by ejdanderson 3 years ago.
Filter args as optional parameters.

Download all attachments as: .zip

Change History (17)

comment:1 goto104 years ago

  • Cc goto10 added

comment:2 lumination4 years ago

  • Component changed from General to Plugins

comment:3 nacin4 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.

solarissmoke3 years ago

comment:4 solarissmoke3 years ago

  • Keywords has-patch added; needs-patch removed

comment:5 nacin3 years ago

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

solarissmoke3 years ago

comment:6 solarissmoke3 years ago

Oops, yeah, bit slow this morning :)

ejdanderson3 years ago

Filter args as optional parameters.

comment:7 markjaquith3 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 3 years ago by markjaquith (previous) (diff)

comment:8 SergeyBiryukov3 years ago

  • Milestone changed from Future Release to 3.3

comment:9 markjaquith3 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

comment:10 duck_3 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.

comment:11 toscho14 months ago

  • Cc info@… added

comment:12 nacin8 months ago

#26084 was marked as a duplicate.

comment:13 nacin5 months ago

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

comment:14 nacin5 months ago

  • Component changed from Admin APIs to Plugins

Sorry for the noise.

Note: See TracTickets for help on using tickets.