register_setting() sanitisation callback two argument backwards incompatibility
|Reported by:||duck_||Owned by:||duck_|
See #15335 and  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.