From 243d449cf38015a1d84b25a4913526132c1a35c1 Mon Sep 17 00:00:00 2001 From: Glomberg Date: Fri, 3 Apr 2026 12:30:18 +0300 Subject: [PATCH 1/2] Fix. WPMS. Errors output for WPMS mutual-mutual mode fixed. --- lib/Cleantalk/ApbctWP/State.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Cleantalk/ApbctWP/State.php b/lib/Cleantalk/ApbctWP/State.php index 92a01c04f..46de235b2 100644 --- a/lib/Cleantalk/ApbctWP/State.php +++ b/lib/Cleantalk/ApbctWP/State.php @@ -652,8 +652,10 @@ protected function init() // Get stats from main blog switch_to_blog(get_main_site_id()); $main_blog_stats = get_option($this->option_prefix . '_stats'); + $main_blog_errors = get_option($this->option_prefix . '_errors'); restore_current_blog(); $this->stats = $main_blog_stats; + $this->errors = $main_blog_errors; $this->api_key = $this->network_settings['apikey']; $this->key_is_ok = $this->network_data['key_is_ok']; $this->user_token = $this->network_data['user_token']; From cac846858acb599b51f0065f4b8c39f83a6385c8 Mon Sep 17 00:00:00 2001 From: Glomberg Date: Fri, 3 Apr 2026 14:53:36 +0300 Subject: [PATCH 2/2] Fix. Code. Unit test added: check errors array in State. --- lib/Cleantalk/ApbctWP/State.php | 2 +- tests/ApbctWP/TestState.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Cleantalk/ApbctWP/State.php b/lib/Cleantalk/ApbctWP/State.php index 46de235b2..e7c534127 100644 --- a/lib/Cleantalk/ApbctWP/State.php +++ b/lib/Cleantalk/ApbctWP/State.php @@ -649,7 +649,7 @@ protected function init() // Network with Mutual Access key if ( ! is_main_site() && $this->network_settings['multisite__work_mode'] == 2 ) { - // Get stats from main blog + // Get stats and errors from main blog switch_to_blog(get_main_site_id()); $main_blog_stats = get_option($this->option_prefix . '_stats'); $main_blog_errors = get_option($this->option_prefix . '_errors'); diff --git a/tests/ApbctWP/TestState.php b/tests/ApbctWP/TestState.php index aa413ad8d..cf00a45cf 100644 --- a/tests/ApbctWP/TestState.php +++ b/tests/ApbctWP/TestState.php @@ -22,6 +22,7 @@ public function testIsHaveErrors_haveErrors() update_option( 'cleantalk_errors', array( 'error_type' => 'Error text' ) ); $apbct = new State( 'cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats') ); $this->assertTrue( $apbct->isHaveErrors() ); + delete_option('cleantalk_errors'); } public function testIsHaveErrors_emptyErrors() @@ -29,6 +30,7 @@ public function testIsHaveErrors_emptyErrors() update_option( 'cleantalk_errors', array() ); $apbct = new State( 'cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats') ); $this->assertFalse( $apbct->isHaveErrors() ); + delete_option('cleantalk_errors'); } public function testIsHaveErrors_emptyInnerErrors() @@ -36,6 +38,7 @@ public function testIsHaveErrors_emptyInnerErrors() update_option( 'cleantalk_errors', array( 'error_type' => array() ) ); $apbct = new State( 'cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats') ); $this->assertFalse( $apbct->isHaveErrors() ); + delete_option('cleantalk_errors'); } public function testIsHaveErrors_filledInnerErrors() @@ -43,6 +46,20 @@ public function testIsHaveErrors_filledInnerErrors() update_option( 'cleantalk_errors', array( 'error_type' => array( 'error_text' => 'Error text' ) ) ); $apbct = new State( 'cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats') ); $this->assertTrue( $apbct->isHaveErrors() ); + delete_option('cleantalk_errors'); + } + + public function testErrorsArrayFromState() + { + $apbct = new State('cleantalk', array('errors')); + + $apbct->errorAdd('api', 'error'); + + $errors_from_state = (array) $apbct->errors; + + $this->assertArrayHasKey('api', $errors_from_state); + $this->assertArrayHasKey('error', $errors_from_state['api'][0]); + $this->assertArrayHasKey('error_time', $errors_from_state['api'][0]); } //UpdateVars section @@ -58,6 +75,7 @@ public function testAutoSaveVars__remote_calls(){ apbct_run_update_actions('6.1','6.2'); $db_result = get_option('cleantalk_remote_calls')['post_api_key']; $this->assertEquals(array ('last_call' => 0,), $db_result); + delete_option('cleantalk_remote_calls'); } public function testAutoSaveVars__settings(){ @@ -71,6 +89,7 @@ public function testAutoSaveVars__settings(){ apbct_run_update_actions('6.1','6.2'); $db_result = get_option('cleantalk_settings')['forms__registrations_test']; $this->assertEquals(1, $db_result); + delete_option('cleantalk_settings'); } public function testAutoSaveVars__data(){ @@ -84,6 +103,7 @@ public function testAutoSaveVars__data(){ apbct_run_update_actions('6.1','6.2'); $db_result = get_option('cleantalk_data')['js_key_lifetime']; $this->assertEquals(86400, $db_result); + delete_option('cleantalk_data'); } public function testAutoSaveVars__network_settings(){ @@ -97,6 +117,7 @@ public function testAutoSaveVars__network_settings(){ apbct_run_update_actions('6.1','6.2'); $db_result = get_option('cleantalk_network_settings')['multisite__white_label__plugin_name']; $this->assertEquals('Anti-Spam by CleanTalk', $db_result); + delete_option('network_settings'); } public function testAutoSaveVars__network_data(){ @@ -110,6 +131,7 @@ public function testAutoSaveVars__network_data(){ apbct_run_update_actions('6.1','6.2'); $db_result = get_option('cleantalk_network_data')['moderate']; $this->assertEquals(0, $db_result); + delete_option('cleantalk_network_data'); } public function testAutoSaveVars__stats(){ @@ -161,6 +183,7 @@ public function testAutoSaveVars__stats(){ $this->assertEquals(14400, $db_result); $db_result = get_option('cleantalk_stats')['sfw']['sending_logs__timestamp']; $this->assertEquals(10000, $db_result); + delete_option('cleantalk_stats'); } @@ -175,6 +198,7 @@ public function testAutoSaveVars__fw_stats(){ apbct_run_update_actions('6.1','6.2'); $db_result = get_option('cleantalk_fw_stats')['firewall_updating_id']; $this->assertEquals(null, $db_result); + delete_option('cleantalk_fw_stats'); } public function testAutoSaveVars__fw_stats_await_exception_without_var_updater(){ @@ -191,5 +215,6 @@ public function testAutoSaveVars__fw_stats_await_exception_without_var_updater() //await udefined index $this->expectException(Notice::class); $db_result = get_option('cleantalk_fw_stats')['firewall_updating_id']; + delete_option('cleantalk_fw_stats'); } }