Opened 7 years ago
Closed 7 years ago
#44956 closed defect (bug) (fixed)
Prevent `update_network_option()` from updating when the old and new values contain identical objects.
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.1 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Networks and Sites | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
When an object is included in an option, passing an unchanged value to update_network_option will trigger an UPDATE query.
Given the data below, the meta_data will have a different resource ID for the old and new values. $value === $old_value will always evaluate untrue and the database will be updated and the caches cleared.
array(2) {
["url"]=>
string(85) "http://src.wordpress-develop.dev/wp-content/uploads/2016/10/cropped-Blurry-Lights.jpg"
["meta_data"]=>
object(stdClass)#370 (3) {
["attachment_id"]=>
int(292)
["height"]=>
int(708)
["width"]=>
int(1260)
}
}
Attachments (3)
Change History (8)
#2
@
7 years ago
Code snippet to demonstrate why the proposed patch works:
<?php $x = array( 'url' => 'http://src.wordpress-develop.dev/wp-content/uploads/2016/10/cropped-Blurry-Lights.jpg', 'meta_data' => (object) array( 'attachment_id' => 292, 'height' => 708, 'width' => 1260, ), ); $y = array( 'url' => 'http://src.wordpress-develop.dev/wp-content/uploads/2016/10/cropped-Blurry-Lights.jpg', 'meta_data' => (object) array( 'attachment_id' => 292, 'height' => 708, 'width' => 1260, ), ); var_dump( $x === $y ); var_dump( serialize( $x ) === serialize( $y ) );
Output:
bash bor0@boro:~/dev/www/wordpress$ php test.php bool(false) bool(true)
#3
@
7 years ago
- Keywords needs-unit-tests added
- Milestone changed from 5.0 to 5.1
@bor0 Thanks for providing a patch. I've punted this to the 5.1 milestone due to the focus on the new editor for 5.0.
[39564] included a unit test for update_option(). It would be great to include a similar test for update_network_option().
Note: See
TracTickets for help on using
tickets.
Ccing @SergeyBiryukov for visibility.