From 50065e4a75e46e1486cf35a628ebf3d476e94bd7 Mon Sep 17 00:00:00 2001 From: Kader Ibrahim S Date: Thu, 9 May 2024 17:35:21 +0530 Subject: [PATCH 1/4] Adds remove dismissable notices method --- .../php/compat-checker/src/Checks/CompatCheck.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/php/compat-checker/src/Checks/CompatCheck.php b/packages/php/compat-checker/src/Checks/CompatCheck.php index 738681d3..601f3482 100644 --- a/packages/php/compat-checker/src/Checks/CompatCheck.php +++ b/packages/php/compat-checker/src/Checks/CompatCheck.php @@ -172,4 +172,19 @@ public function is_compatible( $plugin_data ) { add_action( 'admin_notices', [ $this, 'display_admin_notices' ], 20 ); return $this->run_checks(); } + + /** + * Remove dismissable notices. + */ + public function remove_dismissable_notices() { + if ( class_exists( WC_Admin_Notices::class ) ) { + $plugin_basename = plugin_basename( $this->plugin_data['File'] ); + $all_notices = WC_Admin_Notices::get_notices(); + foreach ( $all_notices as $notice_name ) { + if ( true === str_starts_with( $notice_name, $plugin_basename ) ) { + WC_Admin_Notices::remove_notice( $notice_name ); + } + } + } + } } From 701de6e6d177466bcc656949636983f7c82208d4 Mon Sep 17 00:00:00 2001 From: Kader Ibrahim S Date: Thu, 9 May 2024 17:39:29 +0530 Subject: [PATCH 2/4] Hooks dismissable notices method to deactivation hook. --- packages/php/compat-checker/src/Checker.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/php/compat-checker/src/Checker.php b/packages/php/compat-checker/src/Checker.php index 749e8141..496ddee7 100644 --- a/packages/php/compat-checker/src/Checker.php +++ b/packages/php/compat-checker/src/Checker.php @@ -81,7 +81,17 @@ public function is_compatible( $plugin_file_path, $file_version ) { ]; $plugin_data = $this->get_plugin_data( $plugin_file_path, $file_version ); $plugin_basename = plugin_basename( $plugin_file_path ); + + // Remove dismissable notices on plugin deactivation. + register_deactivation_hook( + $plugin_file_path, + array( + WCCompatibility::instance( $plugin_basename ), + 'remove_dismissable_notices', + ) + ); + // Run all compatibility checks. foreach ( $checks as $compatibility ) { if ( ! $compatibility::instance( $plugin_basename )->is_compatible( $plugin_data ) ) { return false; From 4107a875e8be4896ce8be3cdd1f7dc5c264fa2a2 Mon Sep 17 00:00:00 2001 From: Kader Ibrahim S Date: Thu, 9 May 2024 17:45:50 +0530 Subject: [PATCH 3/4] Fixes `Squiz.WhiteSpace.SuperfluousWhitespace.EndLine` lint error --- packages/php/compat-checker/src/Checker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/php/compat-checker/src/Checker.php b/packages/php/compat-checker/src/Checker.php index 496ddee7..4d6a4469 100644 --- a/packages/php/compat-checker/src/Checker.php +++ b/packages/php/compat-checker/src/Checker.php @@ -81,7 +81,7 @@ public function is_compatible( $plugin_file_path, $file_version ) { ]; $plugin_data = $this->get_plugin_data( $plugin_file_path, $file_version ); $plugin_basename = plugin_basename( $plugin_file_path ); - + // Remove dismissable notices on plugin deactivation. register_deactivation_hook( $plugin_file_path, From f6d53ecb8b49866b3d414b755f13995376874e40 Mon Sep 17 00:00:00 2001 From: Kader Ibrahim S Date: Thu, 9 May 2024 17:46:43 +0530 Subject: [PATCH 4/4] Fixes `Generic.Arrays.DisallowLongArraySyntax.Found` lint error --- packages/php/compat-checker/src/Checker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/php/compat-checker/src/Checker.php b/packages/php/compat-checker/src/Checker.php index 4d6a4469..145937b0 100644 --- a/packages/php/compat-checker/src/Checker.php +++ b/packages/php/compat-checker/src/Checker.php @@ -85,10 +85,10 @@ public function is_compatible( $plugin_file_path, $file_version ) { // Remove dismissable notices on plugin deactivation. register_deactivation_hook( $plugin_file_path, - array( + [ WCCompatibility::instance( $plugin_basename ), 'remove_dismissable_notices', - ) + ] ); // Run all compatibility checks.