From ef837b020b8363e62b0b177484841cfd0a279681 Mon Sep 17 00:00:00 2001 From: Ryan Fredlund Date: Mon, 2 Mar 2020 22:26:44 +0100 Subject: [PATCH] Remove setting from site option when deleting plugin --- wp-autoupdates.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/wp-autoupdates.php b/wp-autoupdates.php index b5a8a06..6538c38 100755 --- a/wp-autoupdates.php +++ b/wp-autoupdates.php @@ -290,6 +290,25 @@ function wp_autoupdates_plugins_bulk_actions_handle( $redirect_to, $doaction, $i add_action( 'handle_bulk_actions-plugins', 'wp_autoupdates_plugins_bulk_actions_handle', 10, 3 ); +/** + * Handle cleanup when plugin deleted + */ +function wp_autoupdates_plugin_deleted( $plugin_file, $deleted ) { + // Do nothing if the plugin wasn't deleted + if ( ! $deleted ) { + return; + } + + // Remove settings + $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); + if ( in_array( $plugin_file, $wp_auto_update_plugins, true ) ) { + $wp_auto_update_plugins = array_diff( $wp_auto_update_plugins, array( $plugin_file ) ); + update_site_option( 'wp_auto_update_plugins', $wp_auto_update_plugins ); + } +} +add_action( 'deleted_plugin', 'wp_autoupdates_plugin_deleted', 10, 2 ); + + /** * Auto-update notices */