Skip to content

Commit a41fd06

Browse files
author
costdev
committed
Yoast BC fix (don't commit with this in the PR)
1 parent 7c28426 commit a41fd06

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

src/wp-includes/option.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ function update_network_option( $network_id, $option, $value ) {
21742174
return false;
21752175
}
21762176

2177-
if ( $default_value === $raw_old_value ) {
2177+
if ( false === $old_value ) {
21782178
return add_network_option( $network_id, $option, $value );
21792179
}
21802180

tests/phpunit/tests/option/networkOption.php

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,12 @@ public function test_update_network_option_should_conditionally_apply_site_and_o
795795
public function test_update_network_option_should_add_option_with_filtered_default_value() {
796796
global $wpdb;
797797

798-
$option = 'foo';
799-
$default_site_value = 'default-site-value';
800-
$default_option_value = 'default-option-value';
798+
if ( ! is_multisite() ) {
799+
$this->markTestSkipped();
800+
}
801+
802+
$option = 'foo';
803+
$default_site_value = 'default-site-value';
801804

802805
add_filter(
803806
"default_site_option_{$option}",
@@ -806,40 +809,15 @@ static function () use ( $default_site_value ) {
806809
}
807810
);
808811

809-
add_filter(
810-
"default_option_{$option}",
811-
static function () use ( $default_option_value ) {
812-
return $default_option_value;
813-
}
814-
);
815-
816-
/*
817-
* For a non existing option with the unfiltered default of false, passing false here wouldn't work.
818-
* Because the default is different than false here though, passing false is expected to result in
819-
* a database update.
820-
*/
821-
$this->assertTrue( update_network_option( null, $option, false ), 'update_network_option() should have returned true.' );
822-
823-
if ( is_multisite() ) {
824-
$actual = $wpdb->get_row(
825-
$wpdb->prepare(
826-
"SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s LIMIT 1",
827-
$option
828-
)
829-
);
830-
} else {
831-
$actual = $wpdb->get_row(
832-
$wpdb->prepare(
833-
"SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1",
834-
$option
835-
)
836-
);
837-
}
812+
$this->assertFalse( update_network_option( null, $option, false ), 'update_network_option() should have returned false.' );
838813

839-
$value_field = is_multisite() ? 'meta_value' : 'option_value';
814+
$actual = $wpdb->get_row(
815+
$wpdb->prepare(
816+
"SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s LIMIT 1",
817+
$option
818+
)
819+
);
840820

841-
$this->assertIsObject( $actual, 'The option was not added to the database.' );
842-
$this->assertObjectHasProperty( $value_field, $actual, "The '$value_field' property was not included." );
843-
$this->assertSame( '', $actual->$value_field, 'The new value was not stored in the database.' );
821+
$this->assertNull( $actual, 'The option was added to the database.' );
844822
}
845823
}

0 commit comments

Comments
 (0)