diff --git a/packages/php/compat-checker/src/Checker.php b/packages/php/compat-checker/src/Checker.php index 749e8141..145937b0 100644 --- a/packages/php/compat-checker/src/Checker.php +++ b/packages/php/compat-checker/src/Checker.php @@ -82,6 +82,16 @@ 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, + [ + 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; 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 ); + } + } + } + } }