Opened 14 years ago
Closed 14 years ago
#18914 closed defect (bug) (fixed)
register_setting() sanitisation callback two argument backwards incompatibility
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.3 | Priority: | high |
Severity: | major | Version: | 3.3 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
See #15335 and [18887] for the introduction of always passing two arguments to the sanitisation callback. This is a problem because it breaks plugins which use register_setting with a sanitisation callback which chokes on the 2nd argument being introduced. An example of this is provided on the codex:
register_setting( 'my_options_group', 'my_option_name', 'intval' );
One plugin which uses this is bbPress. I was able trigger this on activation on a fresh install:
Warning: intval() expects parameter 2 to be long, string given in wp-includes/plugin.php on line 170 call_user_func_array('intval', array (0 => '5', 1 => '_bbp_edit_lock')) wp-includes/plugin.php:170
Attached is a patch to revert the change.
The only issue is how to address the reason for the code change: "You should be able to have a generic save handler that does a switch on the option name and does your sanitization magic." A generic sanitize_option filter would do it, but would incur some overhead on having the "generic save handler" called for every option.
I propose another approach - add extra param to
register_setting()
, so user would be able to decide if it wants to get option name or not. I have implemented this in attached patch.