diff --git src/wp-includes/option.php src/wp-includes/option.php
index ac17c2f..66fb6e4 100644
|
|
function update_option( $option, $value, $autoload = null ) { |
295 | 295 | */ |
296 | 296 | $value = apply_filters( 'pre_update_option', $value, $option, $old_value ); |
297 | 297 | |
298 | | // If the new and old values are the same, no need to update. |
299 | | if ( $value === $old_value ) |
| 298 | /* |
| 299 | * If the new and old values are the same, no need to update. |
| 300 | * |
| 301 | * Unserialized values will be adequate in most cases. If the unserialized |
| 302 | * data differs, the (maybe) serialized data is checked to avoid |
| 303 | * unnecessary database calls for otherwise identical object instances. |
| 304 | * |
| 305 | * See https://core.trac.wordpress.org/ticket/38903 |
| 306 | */ |
| 307 | if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
300 | 308 | return false; |
| 309 | } |
301 | 310 | |
302 | 311 | /** This filter is documented in wp-includes/option.php */ |
303 | 312 | if ( apply_filters( 'default_option_' . $option, false, $option, false ) === $old_value ) { |
diff --git tests/phpunit/tests/option/updateOption.php tests/phpunit/tests/option/updateOption.php
index 32ae5e5..eb85b12 100644
|
|
class Tests_Option_UpdateOption extends WP_UnitTestCase { |
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
| 169 | * @ticket 38903 |
| 170 | */ |
| 171 | public function test_update_option_array_with_object() { |
| 172 | $array_w_object = array( |
| 173 | 'url' => 'http://src.wordpress-develop.dev/wp-content/uploads/2016/10/cropped-Blurry-Lights.jpg', |
| 174 | 'meta_data' => (object) array( |
| 175 | 'attachment_id' => 292, |
| 176 | 'height' => 708, |
| 177 | 'width' => 1260, |
| 178 | ), |
| 179 | ); |
| 180 | |
| 181 | // Add the option, it did not exist before this. |
| 182 | add_option( 'array_w_object', $array_w_object ); |
| 183 | |
| 184 | $num_queries_pre_update = get_num_queries(); |
| 185 | |
| 186 | // Update the option using the same array with an object for the value. |
| 187 | $this->assertFalse( update_option( 'array_w_object', $array_w_object ) ); |
| 188 | |
| 189 | // Check that no new database queries were performed. |
| 190 | $this->assertEquals( $num_queries_pre_update, get_num_queries() ); |
| 191 | } |
| 192 | |
| 193 | /** |
169 | 194 | * `add_filter()` callback for test_should_respect_default_option_filter_when_option_does_not_yet_exist_in_database(). |
170 | 195 | */ |
171 | 196 | public function __return_foo() { |