Skip to content

Commit 207a7e9

Browse files
committed
Bug fixed in the "update_site_option" callback in the Settings connector class.
1 parent 52fd0d4 commit 207a7e9

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"license": "GPL-2.0-or-later",
77
"repositories": [
88
{
9-
"type":"composer",
10-
"url":"https://wpackagist.org"
9+
"type": "composer",
10+
"url": "https://wpackagist.org"
1111
}
1212
],
1313
"require": {

connectors/class-connector-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ public function callback_update_option_permalink_structure( $old_value, $value )
664664
* @param mixed $old_value Option old value.
665665
*/
666666
public function callback_update_site_option( $option, $value, $old_value ) {
667-
$this->callback_updated_option( $option, $value, $old_value );
667+
$this->callback_updated_option( $option, $old_value, $value );
668668
}
669669

670670
/**

tests/tests/connectors/test-class-connector-settings.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ public function test_is_option_ignored() {
4747
}
4848

4949
public function test_callback_updated_option() {
50+
// If multisite use site_option methods and test "update_site_option" callback
51+
// instead of the update_option callback.
52+
$add_method = is_multisite() ? 'add_site_option' : 'add_option';
53+
$update_method = is_multisite() ? 'update_site_option' : 'update_option';
54+
5055
// Create options in database for later use.
51-
add_option( 'users_can_register', false );
52-
add_option( 'permalink_structure', '' );
53-
add_option( 'category_base', '' );
54-
add_option( 'tag_base', '' );
56+
call_user_func( $add_method, 'users_can_register', 0 );
57+
call_user_func( $add_method, 'permalink_structure', '' );
58+
call_user_func( $add_method, 'category_base', '' );
59+
call_user_func( $add_method, 'tag_base', '' );
5560

5661
$this->mock->expects( $this->exactly( 4 ) )
5762
->method( 'log' )
@@ -123,22 +128,26 @@ public function test_callback_updated_option() {
123128
do_action( 'customize_save', new \WP_Customize_Manager( array() ) );
124129

125130
// Update options to trigger callback.
126-
update_option( 'users_can_register', true );
131+
call_user_func( $update_method, 'users_can_register', 1 );
127132

128133
// Use this to prevent repeated log calls.
129134
global $wp_actions;
130135
unset( $wp_actions['customize_save'] );
131136

132-
update_option( 'permalink_structure', '/%year%/%postname%/' );
133-
update_option( 'category_base', 'cat/' );
134-
update_option( 'tag_base', 'tag/' );
135-
136-
137-
// Check callback test action.
138-
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_updated_option' ) );
139-
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_tag_base' ) );
140-
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_category_base' ) );
141-
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_permalink_structure' ) );
142-
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option' ) );
137+
call_user_func( $update_method, 'permalink_structure', '/%year%/%postname%/' );
138+
call_user_func( $update_method, 'category_base', 'cat/' );
139+
call_user_func( $update_method, 'tag_base', 'tag/' );
140+
141+
// If multisite only check update_site_option test callback.
142+
if ( is_multisite() ) {
143+
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_site_option' ) );
144+
} else {
145+
// Check callback test action.
146+
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option_tag_base' ) );
147+
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option_category_base' ) );
148+
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option_permalink_structure' ) );
149+
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_updated_option' ) );
150+
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option' ) );
151+
}
143152
}
144153
}

0 commit comments

Comments
 (0)