diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php
index 1c0d88225e..21a09bbd51 100644
a
|
b
|
function update_network_option( $network_id, $option, $value ) { |
1583 | 1583 | */ |
1584 | 1584 | $value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $network_id ); |
1585 | 1585 | |
1586 | | if ( $value === $old_value ) { |
| 1586 | /* |
| 1587 | * If the new and old values are the same, no need to update. |
| 1588 | * |
| 1589 | * Unserialized values will be adequate in most cases. If the unserialized |
| 1590 | * data differs, the (maybe) serialized data is checked to avoid |
| 1591 | * unnecessary database calls for otherwise identical object instances. |
| 1592 | * |
| 1593 | * See https://core.trac.wordpress.org/ticket/44956 |
| 1594 | */ |
| 1595 | if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
1587 | 1596 | return false; |
1588 | 1597 | } |
1589 | 1598 | |
diff --git a/tests/phpunit/tests/option/networkOption.php b/tests/phpunit/tests/option/networkOption.php
index 637ff5732a..244ea43898 100644
a
|
b
|
class Tests_Option_NetworkOption extends WP_UnitTestCase { |
169 | 169 | |
170 | 170 | $this->assertSame( array( 'this_does_not_exist' => true ), $cache ); |
171 | 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Ensure updating network options containing an object do not result in unneeded database calls. |
| 175 | * |
| 176 | * @ticket 44956 |
| 177 | */ |
| 178 | public function test_update_network_option_array_with_object() { |
| 179 | $array_w_object = array( |
| 180 | 'url' => 'http://src.wordpress-develop.dev/wp-content/uploads/2016/10/cropped-Blurry-Lights.jpg', |
| 181 | 'meta_data' => (object) array( |
| 182 | 'attachment_id' => 292, |
| 183 | 'height' => 708, |
| 184 | 'width' => 1260, |
| 185 | ), |
| 186 | ); |
| 187 | |
| 188 | $array_w_object_2 = array( |
| 189 | 'url' => 'http://src.wordpress-develop.dev/wp-content/uploads/2016/10/cropped-Blurry-Lights.jpg', |
| 190 | 'meta_data' => (object) array( |
| 191 | 'attachment_id' => 292, |
| 192 | 'height' => 708, |
| 193 | 'width' => 1260, |
| 194 | ), |
| 195 | ); |
| 196 | |
| 197 | // Add the option, it did not exist before this. |
| 198 | add_network_option( null, 'array_w_object', $array_w_object ); |
| 199 | |
| 200 | $num_queries_pre_update = get_num_queries(); |
| 201 | |
| 202 | // Update the option using the same array with an object for the value. |
| 203 | $this->assertFalse( update_network_option( null, 'array_w_object', $array_w_object_2 ) ); |
| 204 | |
| 205 | // Check that no new database queries were performed. |
| 206 | $this->assertEquals( $num_queries_pre_update, get_num_queries() ); |
| 207 | } |
172 | 208 | } |