Skip to content

Commit

Permalink
Fixes admin notices not removed on plugin deactivation (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibndawood authored May 9, 2024
2 parents 1441c00 + f6d53ec commit ba99381
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/php/compat-checker/src/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions packages/php/compat-checker/src/Checks/CompatCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
}
}

0 comments on commit ba99381

Please sign in to comment.