[wp-trac] [WordPress Trac] #21989: update_option() calls sanitize_option() twice when option does not exist
WordPress Trac
noreply at wordpress.org
Sat Nov 26 22:45:56 UTC 2022
#21989: update_option() calls sanitize_option() twice when option does not exist
-------------------------------------------------+-------------------------
Reporter: MikeSchinkel | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
| Release
Component: Options, Meta APIs | Version:
Severity: normal | Resolution:
Keywords: dev-feedback has-patch needs- | Focuses:
testing | performance
-------------------------------------------------+-------------------------
Comment (by costdev):
Curious, in `add_option()`, what if we wrap this
line[https://github.com/WordPress/wordpress-develop/blob/6.1/src/wp-
includes/option.php#L638 this line] with a check on `did_filter` for the
option?
{{{#!php
if ( ! did_filter( "sanitize_option_{$option}" ) ) {
$value = sanitize_option( $option, $value );
}
}}}
That way, if the value for the option has already been sanitized by the
time it reaches `add_option()`, skip sanitizing it again.
[https://gist.github.com/costdev/fdb4f8669fe204cce6ce9ffc28b4fd0b Here's a
plugin] with a basic test.
Without the above change:
- `sanitize_option()` runs twice.
- `add_option()` saves `a_string_1_1`.
With the above change:
- `sanitize_option()` runs once.
- `add_option()` saves `a_string_1`.
- All hooks that should fire continue to do so, with the expected value.
(Confidence check me on this)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/21989#comment:32>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list