-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug when comparing options that have a pre filter. #5313
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -776,6 +776,24 @@ function update_option( $option, $value, $autoload = null ) { | |||||
*/ | ||||||
$value = apply_filters( 'pre_update_option', $value, $option, $old_value ); | ||||||
|
||||||
/* | ||||||
* To get the actual raw old value from the database, any existing pre filters need to be temporarily disabled. | ||||||
* Immediately after getting the raw value, they are reinstated. | ||||||
* The raw value is only used to determine whether a value is present in the database. It is not used anywhere | ||||||
* else, and is not passed to any of the hooks either. | ||||||
*/ | ||||||
if ( has_filter( "pre_option_{$option}" ) ) { | ||||||
global $wp_filter; | ||||||
|
||||||
$old_filters = $wp_filter[ "pre_option_{$option}" ]; | ||||||
unset( $wp_filter[ "pre_option_{$option}" ] ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Could we use this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @spacedmonkey I tried it, but the problem is that it also calls the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment saying why we didnt use |
||||||
|
||||||
$raw_old_value = get_option( $option ); | ||||||
$wp_filter[ "pre_option_{$option}" ] = $old_filters; | ||||||
spacedmonkey marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} else { | ||||||
$raw_old_value = $old_value; | ||||||
} | ||||||
|
||||||
/** This filter is documented in wp-includes/option.php */ | ||||||
$default_value = apply_filters( "default_option_{$option}", false, $option, false ); | ||||||
|
||||||
|
@@ -787,11 +805,11 @@ function update_option( $option, $value, $autoload = null ) { | |||||
* | ||||||
* See https://core.trac.wordpress.org/ticket/38903 and https://core.trac.wordpress.org/ticket/22192. | ||||||
*/ | ||||||
if ( $old_value !== $default_value && _is_equal_database_value( $old_value, $value ) ) { | ||||||
if ( $raw_old_value !== $default_value && _is_equal_database_value( $raw_old_value, $value ) ) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
if ( $old_value === $default_value ) { | ||||||
if ( $raw_old_value === $default_value ) { | ||||||
|
||||||
// Default setting for new options is 'yes'. | ||||||
if ( null === $autoload ) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the
pre_option
filter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spacedmonkey I agree that in principle there could be the same bug due to usage of
pre_option
too, but I intentionally did not consider the generalpre_option
filter, because it may have wider reaching implications, so I think unhooking it temporarily is too risky.There's a good chance that a site that uses that filter has some special mechanisms in place for retrieving and storing options that shouldn't be unhooked.
That is different with the
pre_option_{$option}
filter, which is clearly about specific options.