[wp-trac] [WordPress Trac] #61631: sanitize_option_{$option} inconsistencies
WordPress Trac
noreply at wordpress.org
Thu Jul 11 13:54:27 UTC 2024
#61631: sanitize_option_{$option} inconsistencies
--------------------------------+------------------------------
Reporter: liedekef | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version: 6.5.5
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------------+------------------------------
Comment (by liedekef):
In the example on
https://developer.wordpress.org/reference/hooks/sanitize_option_option/ ,
the function sanitize_email takes 2 arguments, so then that needs to be
corrected:
{{{
function sanitize_email($value, $option) {
//...
}
}}}
Concerning register_setting: many people use an array that contains all
their own options (just separate options) and use that logic to call
register_setting:
{{{
foreach ( $options as $opt ) {
register_setting ( 'my-options', $opt, 'my_callback' );
}
}}}
Because certain options need different sanitizing, it requires different
callback functions to be created currently, with if-statements inside the
foreach. And since some options are arrays on their own, it requires yet
more logic.
If the callback had the option name added, developers could do with just 1
callback function and put the logic in there. Currently my way around this
limitation is:
{{{
foreach ( $options as $opt ) {
register_setting ( 'my-options', $opt );
add_filter ( 'sanitize_option_' . $opt, 'my_callback', 10,
2 );
}
}}}
Adding the option name to the callback wouldn't even have any impact on
current filters ...
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61631#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list