From 863ab955fe878ae2f3cf1274b49d4c1bdd56335e Mon Sep 17 00:00:00 2001 From: Tung Du Date: Tue, 10 Mar 2020 12:47:33 +0700 Subject: [PATCH 01/44] feat: add uninstall script --- uninstall.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 uninstall.php diff --git a/uninstall.php b/uninstall.php new file mode 100644 index 000000000..fc6d45faa --- /dev/null +++ b/uninstall.php @@ -0,0 +1,13 @@ + Date: Tue, 10 Mar 2020 12:52:22 +0700 Subject: [PATCH 02/44] feat: update uninstall script comment --- uninstall.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index fc6d45faa..d42441234 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,6 +1,11 @@ Date: Fri, 4 Aug 2023 16:45:59 +0530 Subject: [PATCH 03/44] format: add file doc tags --- uninstall.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index d42441234..f48082b76 100644 --- a/uninstall.php +++ b/uninstall.php @@ -2,7 +2,8 @@ /** * Distributor uninstall script. * - * @since 2.0.0 + * @since x.x.x + * @package distributor */ if ( ! defined( 'ABSPATH' ) || ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { From 620f8efe5697d47ad54147ba997e710d43f69f37 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 4 Aug 2023 17:00:00 +0530 Subject: [PATCH 04/44] fix: add prefix to transient name --- .../InternalConnections/NetworkSiteConnection.php | 2 +- uninstall.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index bed72a97f..3603870c4 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -861,7 +861,7 @@ public static function build_available_authorized_sites( $user_id = false, $cont $last_changed = self::set_sites_last_changed_time(); } - $cache_key = "authorized_sites:$user_id:$context:$last_changed"; + $cache_key = "dt_authorized_sites:$user_id:$context:$last_changed"; $authorized_sites = get_transient( $cache_key ); if ( $force || false === $authorized_sites ) { diff --git a/uninstall.php b/uninstall.php index f48082b76..5625f980c 100644 --- a/uninstall.php +++ b/uninstall.php @@ -17,3 +17,13 @@ delete_option( 'dt_settings' ); delete_option( 'dt_sync_log' ); } + +// Delete options. +$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); + +// Remove transients. +$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); + +// Delete our data from the post and post meta tables. +$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); +$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); From 0f8eaec1c4a3b77d466ca22e5fbe2d871a29e4a0 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 4 Aug 2023 17:00:47 +0530 Subject: [PATCH 05/44] refactor: remove unnecessary code --- uninstall.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/uninstall.php b/uninstall.php index 5625f980c..6aba11545 100644 --- a/uninstall.php +++ b/uninstall.php @@ -10,14 +10,6 @@ die; } -if ( is_multisite() && wp_is_large_network() ) { - delete_site_option( 'dt_settings' ); - delete_site_option( 'dt_sync_log' ); -} else { - delete_option( 'dt_settings' ); - delete_option( 'dt_sync_log' ); -} - // Delete options. $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); From 07d1d3b3440ccf1875776834d79c744c6dbaa993 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 4 Aug 2023 17:01:22 +0530 Subject: [PATCH 06/44] feat: flush cache --- uninstall.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/uninstall.php b/uninstall.php index 6aba11545..5e6a5e701 100644 --- a/uninstall.php +++ b/uninstall.php @@ -19,3 +19,6 @@ // Delete our data from the post and post meta tables. $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); $wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); + +// Clear cache. +wp_cache_flush(); From f79234efe63d4325950dae0f22778b4ad4ff8564 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 4 Aug 2023 18:09:46 +0530 Subject: [PATCH 07/44] refactor: remove unnecessary check --- uninstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index 5e6a5e701..2cb845223 100644 --- a/uninstall.php +++ b/uninstall.php @@ -6,7 +6,7 @@ * @package distributor */ -if ( ! defined( 'ABSPATH' ) || ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { +if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { die; } From 4d1dfad84b8e7cc7b97f79fc833537e31e51bdb1 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 4 Aug 2023 18:15:36 +0530 Subject: [PATCH 08/44] format: improve code formatting --- uninstall.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uninstall.php b/uninstall.php index 2cb845223..a3926bf40 100644 --- a/uninstall.php +++ b/uninstall.php @@ -17,8 +17,8 @@ $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); // Delete our data from the post and post meta tables. -$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); -$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); +$wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); +$wpdb->query( "DELETE FROM $wpdb->postmeta as meta LEFT JOIN $wpdb->posts as posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); // Clear cache. wp_cache_flush(); From fcd4299556da05c18a48bbed319fa115b80574a2 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 4 Aug 2023 18:17:32 +0530 Subject: [PATCH 09/44] format: disable phpcs for uninstall.php --- uninstall.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/uninstall.php b/uninstall.php index a3926bf40..86b39ea94 100644 --- a/uninstall.php +++ b/uninstall.php @@ -6,6 +6,8 @@ * @package distributor */ +// phpcs:disable + if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { die; } @@ -22,3 +24,5 @@ // Clear cache. wp_cache_flush(); + +// phpcs:enable From 1f5caf0b62dba615e3686cd3d5bcf8e33ad119e9 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 4 Aug 2023 18:30:26 +0530 Subject: [PATCH 10/44] fix: define global variable --- uninstall.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uninstall.php b/uninstall.php index 86b39ea94..cffcaa447 100644 --- a/uninstall.php +++ b/uninstall.php @@ -12,6 +12,8 @@ die; } +global $wpdb; + // Delete options. $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); From f8b5fb94e803299ef381a5b750abdaeb6caa6829 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 8 Aug 2023 19:37:28 +0530 Subject: [PATCH 11/44] feat: update last cache update date --- uninstall.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/uninstall.php b/uninstall.php index cffcaa447..df6a3f6ab 100644 --- a/uninstall.php +++ b/uninstall.php @@ -2,8 +2,8 @@ /** * Distributor uninstall script. * - * @since x.x.x * @package distributor + * @since x.x.x */ // phpcs:disable @@ -25,6 +25,8 @@ $wpdb->query( "DELETE FROM $wpdb->postmeta as meta LEFT JOIN $wpdb->posts as posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); // Clear cache. -wp_cache_flush(); +if ( wp_cache_flush() ) { + wp_cache_set_posts_last_changed(); +} // phpcs:enable From e62c579afe64b28168f81a32df20c0a8693d4207 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 8 Aug 2023 19:51:48 +0530 Subject: [PATCH 12/44] feat: delete comment and term data --- uninstall.php | 82 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/uninstall.php b/uninstall.php index df6a3f6ab..31189c401 100644 --- a/uninstall.php +++ b/uninstall.php @@ -12,21 +12,81 @@ die; } -global $wpdb; +/* + * Only remove ALL product and page data if DT_REMOVE_ALL_DATA constant is set to true in user's + * wp-config.php. This is to prevent data loss when deleting the plugin from the backend + * and to ensure only the site owner can perform this action. + */ +if ( defined( 'DT_REMOVE_ALL_DATA' ) && true === DT_REMOVE_ALL_DATA ) { + global $wpdb; + + // Delete options. + $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); + + // Remove transients. + $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); + + // Delete our data from the comment and comment meta tables. + $wpdb->query( + " + DELETE FROM $wpdb->comments as comments + LEFT JOIN $wpdb->posts as posts ON posts.ID = comments.comment_post_ID + WHERE posts.post_type IN ( 'dt_subscription', 'dt_ext_connection' ); + " + ); + $wpdb->query( + " + DELETE meta FROM {$wpdb->commentmeta} meta + LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id + WHERE comments.comment_ID IS NULL; + " + ); + + // Delete our data from the post and post meta tables. + $wpdb->query( + " + DELETE FROM $wpdb->posts + WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' ); + " + ); + $wpdb->query( + " + DELETE FROM $wpdb->postmeta as meta + LEFT JOIN $wpdb->posts as posts ON posts.ID = meta.post_id + WHERE posts.ID IS NULL; + " + ); -// Delete options. -$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); + // Delete orphan relationships. + $wpdb->query( + " + DELETE tr FROM {$wpdb->term_relationships} tr + LEFT JOIN {$wpdb->posts} posts ON posts.ID = tr.object_id + WHERE posts.ID IS NULL;" + ); -// Remove transients. -$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); + // Delete orphan terms. + $wpdb->query( + " + DELETE t FROM {$wpdb->terms} t + LEFT JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id + WHERE tt.term_id IS NULL; + " + ); -// Delete our data from the post and post meta tables. -$wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); -$wpdb->query( "DELETE FROM $wpdb->postmeta as meta LEFT JOIN $wpdb->posts as posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); + // Delete orphan term meta. + $wpdb->query( + " + DELETE tm FROM {$wpdb->termmeta} tm + LEFT JOIN {$wpdb->term_taxonomy} tt ON tm.term_id = tt.term_id + WHERE tt.term_id IS NULL; + " + ); -// Clear cache. -if ( wp_cache_flush() ) { - wp_cache_set_posts_last_changed(); + // Clear cache. + if ( wp_cache_flush() ) { + wp_cache_set_posts_last_changed(); + } } // phpcs:enable From 74ceb30267430ee14fa6127cd4307d1f54ecfa3b Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 8 Aug 2023 21:38:30 +0530 Subject: [PATCH 13/44] fix: remove as from sql query --- uninstall.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uninstall.php b/uninstall.php index 31189c401..298103bc6 100644 --- a/uninstall.php +++ b/uninstall.php @@ -29,8 +29,8 @@ // Delete our data from the comment and comment meta tables. $wpdb->query( " - DELETE FROM $wpdb->comments as comments - LEFT JOIN $wpdb->posts as posts ON posts.ID = comments.comment_post_ID + DELETE FROM $wpdb->comments comments + LEFT JOIN $wpdb->posts posts ON posts.ID = comments.comment_post_ID WHERE posts.post_type IN ( 'dt_subscription', 'dt_ext_connection' ); " ); @@ -51,8 +51,8 @@ ); $wpdb->query( " - DELETE FROM $wpdb->postmeta as meta - LEFT JOIN $wpdb->posts as posts ON posts.ID = meta.post_id + DELETE FROM $wpdb->postmeta meta + LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL; " ); From 034891e509b5f21f517d52e94aa0767ed4f5a0b0 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 8 Aug 2023 21:41:48 +0530 Subject: [PATCH 14/44] fix: resolve sql query issue --- uninstall.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uninstall.php b/uninstall.php index 298103bc6..d21f9ff82 100644 --- a/uninstall.php +++ b/uninstall.php @@ -29,7 +29,7 @@ // Delete our data from the comment and comment meta tables. $wpdb->query( " - DELETE FROM $wpdb->comments comments + DELETE comments FROM $wpdb->comments comments LEFT JOIN $wpdb->posts posts ON posts.ID = comments.comment_post_ID WHERE posts.post_type IN ( 'dt_subscription', 'dt_ext_connection' ); " @@ -51,7 +51,7 @@ ); $wpdb->query( " - DELETE FROM $wpdb->postmeta meta + DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL; " From 65a69b0c86859f4d27d15a098ddf1fe61cb7f937 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 8 Aug 2023 22:13:27 +0530 Subject: [PATCH 15/44] fix: delete only connections and options data --- uninstall.php | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/uninstall.php b/uninstall.php index d21f9ff82..c72ac09d2 100644 --- a/uninstall.php +++ b/uninstall.php @@ -26,22 +26,6 @@ // Remove transients. $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); - // Delete our data from the comment and comment meta tables. - $wpdb->query( - " - DELETE comments FROM $wpdb->comments comments - LEFT JOIN $wpdb->posts posts ON posts.ID = comments.comment_post_ID - WHERE posts.post_type IN ( 'dt_subscription', 'dt_ext_connection' ); - " - ); - $wpdb->query( - " - DELETE meta FROM {$wpdb->commentmeta} meta - LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id - WHERE comments.comment_ID IS NULL; - " - ); - // Delete our data from the post and post meta tables. $wpdb->query( " @@ -57,32 +41,6 @@ " ); - // Delete orphan relationships. - $wpdb->query( - " - DELETE tr FROM {$wpdb->term_relationships} tr - LEFT JOIN {$wpdb->posts} posts ON posts.ID = tr.object_id - WHERE posts.ID IS NULL;" - ); - - // Delete orphan terms. - $wpdb->query( - " - DELETE t FROM {$wpdb->terms} t - LEFT JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id - WHERE tt.term_id IS NULL; - " - ); - - // Delete orphan term meta. - $wpdb->query( - " - DELETE tm FROM {$wpdb->termmeta} tm - LEFT JOIN {$wpdb->term_taxonomy} tt ON tm.term_id = tt.term_id - WHERE tt.term_id IS NULL; - " - ); - // Clear cache. if ( wp_cache_flush() ) { wp_cache_set_posts_last_changed(); From 3d02f1dab32956a34fae1db120805d47416b8acf Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 8 Aug 2023 22:47:26 +0530 Subject: [PATCH 16/44] format: improve code formatting --- uninstall.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/uninstall.php b/uninstall.php index c72ac09d2..68796f384 100644 --- a/uninstall.php +++ b/uninstall.php @@ -27,19 +27,8 @@ $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); // Delete our data from the post and post meta tables. - $wpdb->query( - " - DELETE FROM $wpdb->posts - WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' ); - " - ); - $wpdb->query( - " - DELETE meta FROM $wpdb->postmeta meta - LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id - WHERE posts.ID IS NULL; - " - ); + $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); + $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); // Clear cache. if ( wp_cache_flush() ) { From 543be5e28ace4b6f8b86756ba9a809abd657d178 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Wed, 9 Aug 2023 17:32:16 +0530 Subject: [PATCH 17/44] feat: delete plugin data from post meta table --- uninstall.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/uninstall.php b/uninstall.php index 68796f384..13d08acbf 100644 --- a/uninstall.php +++ b/uninstall.php @@ -30,6 +30,9 @@ $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); + // Delete distributor data from postmeta table. + $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'dt\_%';" ); + // Clear cache. if ( wp_cache_flush() ) { wp_cache_set_posts_last_changed(); From 910ff84de10aad464c1bdb3655dc0391a6ec731a Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Wed, 9 Aug 2023 17:41:26 +0530 Subject: [PATCH 18/44] feat: merge sql query --- uninstall.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/uninstall.php b/uninstall.php index 13d08acbf..e61551f0c 100644 --- a/uninstall.php +++ b/uninstall.php @@ -28,10 +28,7 @@ // Delete our data from the post and post meta tables. $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); - $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); - - // Delete distributor data from postmeta table. - $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'dt\_%';" ); + $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL OR meta.meta_key LIKE 'dt\_%';" ); // Clear cache. if ( wp_cache_flush() ) { From bb7df21cce0a3e6013025fefd6996f77b75d178c Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 22 Sep 2023 17:39:31 +0530 Subject: [PATCH 19/44] feat: dispaly modal when click on plugin deactivaiton link --- includes/bootstrap.php | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 70b8bb3f3..e537b7dda 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -216,6 +216,67 @@ function() { 1 ); + +/** + * Add a deactivation modal when deactivating the plugin. + * + * @since x.x.x + */ +add_action( + 'load-plugins.php', + static function(){ + wp_enqueue_script('jquery-ui-dialog'); + wp_enqueue_style('wp-jquery-ui-dialog'); + + add_action( + 'admin_footer', + static function () { + printf( + '', + esc_html__( 'This is a demo modal', 'distributor' ) + ); + } + ); + + $modal_title = esc_html__( 'Distributor Deactivation', 'distributor' ); + $modal_button_title_deactivate = esc_html__( 'Deactivate', 'distributor' ); + $modal_button_title_cancel = esc_html__( 'Cancel', 'distributor' ); + $script = << Date: Fri, 22 Sep 2023 17:55:24 +0530 Subject: [PATCH 20/44] feat: update deacrtivation modal content --- includes/bootstrap.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index e537b7dda..e749a34d5 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -232,8 +232,11 @@ static function(){ 'admin_footer', static function () { printf( - '', - esc_html__( 'This is a demo modal', 'distributor' ) + '', + esc_html__( 'Would you like to delete all Distributor data?', 'distributor'), + esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ), + 'define(\'DT_REMOVE_ALL_DATA\', true)', + esc_html__( 'Note: This will permanently delete all Distributor data from your database. After deleting Distributor, you can remove code.', 'distributor' ) ); } ); @@ -248,6 +251,7 @@ static function () { $("#my-modal").dialog({ modal: true, title: "$modal_title", + width: 550, buttons: [ { text: "$modal_button_title_cancel", From 71fdbd56e7485664a1a3704d89d209422312c5e1 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Mon, 25 Sep 2023 11:12:21 +0530 Subject: [PATCH 21/44] fix: deactivate modal should not display on sub sites --- includes/bootstrap.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index e749a34d5..ab35ea48c 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -12,6 +12,7 @@ namespace Distributor; +use WP_Screen; use YahnisElsts\PluginUpdateChecker\v5\PucFactory; /** @@ -225,6 +226,13 @@ function() { add_action( 'load-plugins.php', static function(){ + // Exit if deactivating plugin from sub site. + /* @var WP_Screen $screen */ + $screen = get_current_screen(); + if ( ! ( ! is_multisite() || $screen->in_admin( 'network' ) ) ) { + return; + } + wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_style('wp-jquery-ui-dialog'); From d9b4b574a537a0de183dfa88706c4957f7a0a665 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Mon, 25 Sep 2023 11:26:49 +0530 Subject: [PATCH 22/44] doc: update message in modal --- includes/bootstrap.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index ab35ea48c..760a96720 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -244,7 +244,8 @@ static function () { esc_html__( 'Would you like to delete all Distributor data?', 'distributor'), esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ), 'define(\'DT_REMOVE_ALL_DATA\', true)', - esc_html__( 'Note: This will permanently delete all Distributor data from your database. After deleting Distributor, you can remove code.', 'distributor' ) + esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code. +', 'distributor' ) ); } ); From a149f14eddac4dabea3f6cd6631262ec0cb494e7 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Mon, 25 Sep 2023 11:31:05 +0530 Subject: [PATCH 23/44] format: remove extra line --- includes/bootstrap.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 760a96720..9a249cf7d 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -244,8 +244,7 @@ static function () { esc_html__( 'Would you like to delete all Distributor data?', 'distributor'), esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ), 'define(\'DT_REMOVE_ALL_DATA\', true)', - esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code. -', 'distributor' ) + esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code.', 'distributor' ) ); } ); From 09f07b592d5a7da5158bd462aec49814465ce4a5 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Mon, 25 Sep 2023 11:40:05 +0530 Subject: [PATCH 24/44] format: improve code formatting --- .gitignore | 2 ++ includes/bootstrap.php | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 8c357b0ee..be4713c9e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ tests/cypress/reports tests/cypress/downloads distributor.zip + +.github/phpcs-report.xml diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 9a249cf7d..4344bf0f4 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -225,23 +225,22 @@ function() { */ add_action( 'load-plugins.php', - static function(){ + static function() { // Exit if deactivating plugin from sub site. - /* @var WP_Screen $screen */ $screen = get_current_screen(); if ( ! ( ! is_multisite() || $screen->in_admin( 'network' ) ) ) { return; } - wp_enqueue_script('jquery-ui-dialog'); - wp_enqueue_style('wp-jquery-ui-dialog'); + wp_enqueue_script( 'jquery-ui-dialog' ); + wp_enqueue_style( 'wp-jquery-ui-dialog' ); add_action( 'admin_footer', static function () { printf( '', - esc_html__( 'Would you like to delete all Distributor data?', 'distributor'), + esc_html__( 'Would you like to delete all Distributor data?', 'distributor' ), esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ), 'define(\'DT_REMOVE_ALL_DATA\', true)', esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code.', 'distributor' ) @@ -249,10 +248,10 @@ static function () { } ); - $modal_title = esc_html__( 'Distributor Deactivation', 'distributor' ); + $modal_title = esc_html__( 'Distributor Deactivation', 'distributor' ); $modal_button_title_deactivate = esc_html__( 'Deactivate', 'distributor' ); - $modal_button_title_cancel = esc_html__( 'Cancel', 'distributor' ); - $script = << Date: Mon, 15 Jan 2024 11:04:17 +0530 Subject: [PATCH 25/44] Update uninstall.php Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> --- uninstall.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/uninstall.php b/uninstall.php index e61551f0c..271fdb2cb 100644 --- a/uninstall.php +++ b/uninstall.php @@ -31,9 +31,12 @@ $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL OR meta.meta_key LIKE 'dt\_%';" ); // Clear cache. - if ( wp_cache_flush() ) { - wp_cache_set_posts_last_changed(); - } + wp_cache_set_posts_last_changed(); + wp_cache_delete( 'alloptions', 'options' ); + + // The cache for individual posts will need to be removed (it doesn't use last changed) + // The cache for individual options will need to be removed + // On sites will a persistent cache, the transients will need to be removed too } // phpcs:enable From d10a2f733efbfaa928b4289e59b51dcafcbd36cc Mon Sep 17 00:00:00 2001 From: 10upbot on GitHub <10upbot+github@10up.com> Date: Mon, 15 Jan 2024 11:11:10 +0530 Subject: [PATCH 26/44] add: escape data for javascript --- includes/bootstrap.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 4344bf0f4..7a5b5d19c 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -248,9 +248,9 @@ static function () { } ); - $modal_title = esc_html__( 'Distributor Deactivation', 'distributor' ); - $modal_button_title_deactivate = esc_html__( 'Deactivate', 'distributor' ); - $modal_button_title_cancel = esc_html__( 'Cancel', 'distributor' ); + $modal_title = esc_js( esc_html__( 'Distributor Deactivation', 'distributor' ) ); + $modal_button_title_deactivate = esc_js( esc_html__( 'Deactivate', 'distributor' ) ); + $modal_button_title_cancel = esc_js( esc_html__( 'Cancel', 'distributor' ) ); $script = << Date: Mon, 15 Jan 2024 11:21:08 +0530 Subject: [PATCH 27/44] change: use function to regiter deaactivatin modal --- includes/bootstrap.php | 56 ++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 7a5b5d19c..e0e0318e7 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -223,35 +223,33 @@ function() { * * @since x.x.x */ -add_action( - 'load-plugins.php', - static function() { - // Exit if deactivating plugin from sub site. - $screen = get_current_screen(); - if ( ! ( ! is_multisite() || $screen->in_admin( 'network' ) ) ) { - return; - } +function register_deactivation_modal() { + // Exit if deactivating plugin from sub site. + $screen = get_current_screen(); + if ( ! ( ! is_multisite() || $screen->in_admin( 'network' ) ) ) { + return; + } - wp_enqueue_script( 'jquery-ui-dialog' ); - wp_enqueue_style( 'wp-jquery-ui-dialog' ); + wp_enqueue_script( 'jquery-ui-dialog' ); + wp_enqueue_style( 'wp-jquery-ui-dialog' ); - add_action( - 'admin_footer', - static function () { - printf( - '', - esc_html__( 'Would you like to delete all Distributor data?', 'distributor' ), - esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ), - 'define(\'DT_REMOVE_ALL_DATA\', true)', - esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code.', 'distributor' ) - ); - } - ); + add_action( + 'admin_footer', + static function () { + printf( + '', + esc_html__( 'Would you like to delete all Distributor data?', 'distributor' ), + esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ), + 'define(\'DT_REMOVE_ALL_DATA\', true)', + esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code.', 'distributor' ) + ); + } + ); - $modal_title = esc_js( esc_html__( 'Distributor Deactivation', 'distributor' ) ); - $modal_button_title_deactivate = esc_js( esc_html__( 'Deactivate', 'distributor' ) ); - $modal_button_title_cancel = esc_js( esc_html__( 'Cancel', 'distributor' ) ); - $script = << Date: Mon, 22 Jul 2024 21:27:54 +0530 Subject: [PATCH 28/44] delete data for each sub-site when it is a network --- uninstall.php | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/uninstall.php b/uninstall.php index 271fdb2cb..49cbe1dd0 100644 --- a/uninstall.php +++ b/uninstall.php @@ -20,23 +20,37 @@ if ( defined( 'DT_REMOVE_ALL_DATA' ) && true === DT_REMOVE_ALL_DATA ) { global $wpdb; - // Delete options. - $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); - - // Remove transients. - $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); - - // Delete our data from the post and post meta tables. - $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); - $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL OR meta.meta_key LIKE 'dt\_%';" ); - - // Clear cache. - wp_cache_set_posts_last_changed(); - wp_cache_delete( 'alloptions', 'options' ); - - // The cache for individual posts will need to be removed (it doesn't use last changed) - // The cache for individual options will need to be removed - // On sites will a persistent cache, the transients will need to be removed too + // Function to delete data on a specific site + function dt_delete_data() { + global $wpdb; + + // Delete options. + $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); + + // Remove transients. + $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); + + // Delete our data from the post and post meta tables. + $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); + $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL OR meta.meta_key LIKE 'dt\_%';" ); + + // Clear cache. + wp_cache_set_posts_last_changed(); + wp_cache_delete( 'alloptions', 'options' ); + } + + if ( is_multisite() ) { + // Loop through each site in the network + $sites = get_sites(); + foreach ( $sites as $site ) { + switch_to_blog( $site->blog_id ); + dt_delete_data(); + restore_current_blog(); + } + } else { + // Single site + dt_delete_data(); + } } // phpcs:enable From 393ccdbf7ef5c8296bf1e8a5fe081a157852d7a5 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 25 Jul 2024 15:35:05 +0530 Subject: [PATCH 29/44] Delete only subscription data; keeping other posts w/meta --- uninstall.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/uninstall.php b/uninstall.php index 49cbe1dd0..213c8dd6a 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,4 +1,4 @@ -query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); // Remove transients. - $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transients\_dt\_%';" ); + $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient\_dt\_%';" ); - // Delete our data from the post and post meta tables. - $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription', 'dt_ext_connection' );" ); - $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL OR meta.meta_key LIKE 'dt\_%';" ); + // Delete subscription data from the post and post meta tables. + $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription' );" ); + $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); // Clear cache. wp_cache_set_posts_last_changed(); From 25066454a050306d483a5e11876351eb78c91537 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 25 Jul 2024 15:44:31 +0530 Subject: [PATCH 30/44] update the popup notice for more clarity --- includes/bootstrap.php | 6 +++--- uninstall.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index b8b581042..5841bad0f 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -239,9 +239,9 @@ static function () { printf( '', esc_html__( 'Would you like to delete all Distributor data?', 'distributor' ), - esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ), - 'define(\'DT_REMOVE_ALL_DATA\', true)', - esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code.', 'distributor' ) + esc_html__( 'By default, the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well, add the code below to wp-config.php:', 'distributor' ), + 'define( \'DT_REMOVE_ALL_DATA\', true )', + esc_html__( 'After adding this code, the Distributor plugin data will be removed from the website database when deleting the plugin. This will not delete the posts with their metadata other than the subscription. You can review uninstall.php (in the plugin root directory) to learn more about the deleted data. After deleting the Distributor plugin, you can remove the code from the wp-config.php file. Please make sure that this action cannot be undone; take a backup before proceeding.', 'distributor' ) ); } ); diff --git a/uninstall.php b/uninstall.php index 213c8dd6a..07cba68f0 100644 --- a/uninstall.php +++ b/uninstall.php @@ -13,7 +13,7 @@ } /* - * Only remove ALL product and page data if DT_REMOVE_ALL_DATA constant is set to true in user's + * Only remove ALL data if DT_REMOVE_ALL_DATA constant is set to true in user's * wp-config.php. This is to prevent data loss when deleting the plugin from the backend * and to ensure only the site owner can perform this action. */ From 45786f1d72dd8e3816b9eb6269704b1f61b4772a Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 25 Jul 2024 15:52:00 +0530 Subject: [PATCH 31/44] improve query; remove meta first and then posts (only subc) --- uninstall.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/uninstall.php b/uninstall.php index 07cba68f0..11fb05a68 100644 --- a/uninstall.php +++ b/uninstall.php @@ -30,9 +30,11 @@ function dt_delete_data() { // Remove transients. $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient\_dt\_%';" ); - // Delete subscription data from the post and post meta tables. + // Delete post meta entries where the post type is 'dt_subscription' + $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.post_type IN ( 'dt_subscription' );" ); + + // Delete posts of type 'dt_subscription' $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription' );" ); - $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); // Clear cache. wp_cache_set_posts_last_changed(); From 1188c0541dd37f24ed74f687190ac49f03fd12c5 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 25 Jul 2024 15:55:53 +0530 Subject: [PATCH 32/44] remove unnec word --- uninstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index 11fb05a68..f5751177b 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,4 +1,4 @@ -f Date: Thu, 5 Sep 2024 16:59:23 +0530 Subject: [PATCH 33/44] suggestions implemented --- uninstall.php | 109 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 93 insertions(+), 16 deletions(-) diff --git a/uninstall.php b/uninstall.php index f5751177b..e92b47989 100644 --- a/uninstall.php +++ b/uninstall.php @@ -20,37 +20,114 @@ if ( defined( 'DT_REMOVE_ALL_DATA' ) && true === DT_REMOVE_ALL_DATA ) { global $wpdb; - // Function to delete data on a specific site - function dt_delete_data() { + /** + * Function to delete all relevant data from the site (single or multisite). + */ + function dt_delete_data( $is_multisite = false ) { global $wpdb; - // Delete options. - $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'dt\_%';" ); + // Delete post meta and posts of type 'dt_subscription'. + $subscription_post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'dt_subscription';" ); - // Remove transients. - $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient\_dt\_%';" ); + if ( ! empty( $subscription_post_ids ) ) { + $ids_string = implode( ',', array_map( 'intval', $subscription_post_ids ) ); - // Delete post meta entries where the post type is 'dt_subscription' - $wpdb->query( "DELETE meta FROM $wpdb->postmeta meta LEFT JOIN $wpdb->posts posts ON posts.ID = meta.post_id WHERE posts.post_type IN ( 'dt_subscription' );" ); + // Delete subscription meta. + $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids_string);" ); - // Delete posts of type 'dt_subscription' - $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type IN ( 'dt_subscription' );" ); + // Delete subscription posts. + $wpdb->query( "DELETE FROM $wpdb->posts WHERE ID IN ($ids_string);" ); - // Clear cache. - wp_cache_set_posts_last_changed(); - wp_cache_delete( 'alloptions', 'options' ); + // Clear the post cache. + wp_cache_set_posts_last_changed(); + wp_cache_delete_multiple( $subscription_post_ids, 'posts' ); + wp_cache_delete_multiple( $subscription_post_ids, 'post_meta' ); + } + + // Delete relevant options (single or multisite). + delete_site_options( $is_multisite ); + } + + /** + * Delete all relevant options from a site (single or multisite). + */ + function delete_site_options( $is_multisite = false ) { + global $wpdb; + + $option_prefixes = array( + 'dt_', + '_transient_dt_', + '_transient_timeout_dt_', + ); + + // Include multisite-specific prefixes if not a single site. + if ( ! $is_multisite ) { + $option_prefixes[] = '_site_transient_dt_'; + $option_prefixes[] = '_site_transient_timeout_dt_'; + } + + // Determine the appropriate table and column based on multisite or single site. + if ( $is_multisite ) { + $table = $wpdb->sitemeta; + $id_column = 'meta_id'; + $key_column = 'meta_key'; + $site_column = 'site_id'; + $site_id = get_current_network_id(); + } else { + $table = $wpdb->options; + $id_column = 'option_id'; + $key_column = 'option_name'; + } + + // Construct the WHERE clause based on the environment. + $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), "$key_column LIKE %s" ) ); + + // Prepare the query with proper escaping for both single and multisite. + $query = $is_multisite + ? $wpdb->prepare( + "SELECT $id_column FROM $table WHERE $site_column = %d AND ($where_clause);", + array_merge( [ $site_id ], array_map( function( $prefix ) use ( $wpdb ) { + return $wpdb->esc_like( $prefix ) . '%'; + }, $option_prefixes ) ) + ) + : $wpdb->prepare( + "SELECT $id_column FROM $table WHERE $where_clause;", + array_map( function( $prefix ) use ( $wpdb ) { + return $wpdb->esc_like( $prefix ) . '%'; + }, $option_prefixes ) + ); + + // Fetch the options to delete. + $options_to_delete = $wpdb->get_col( $query ); + + if ( ! empty( $options_to_delete ) ) { + $ids_string = implode( ',', array_map( 'intval', $options_to_delete ) ); + + // Delete the options using the retrieved IDs. + $wpdb->query( "DELETE FROM $table WHERE $id_column IN ($ids_string);" ); + + // Flush the relevant caches. + $cache_group = $is_multisite ? 'site-options' : 'options'; + wp_cache_delete_multiple( $options_to_delete, $cache_group ); + + if ( ! $is_multisite ) { + // Flush the alloptions cache if it's a single site. + wp_cache_delete( 'alloptions', 'options' ); + } + } } + // Check if it's a multisite installation. if ( is_multisite() ) { - // Loop through each site in the network + // Loop through each site in the network. $sites = get_sites(); foreach ( $sites as $site ) { switch_to_blog( $site->blog_id ); - dt_delete_data(); + dt_delete_data( true ); restore_current_blog(); } } else { - // Single site + // Single site. dt_delete_data(); } } From e0530b946249bb58e226d6ab6cf42e1742904369 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 5 Sep 2024 17:21:10 +0530 Subject: [PATCH 34/44] improvise the code --- uninstall.php | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/uninstall.php b/uninstall.php index e92b47989..a0893594d 100644 --- a/uninstall.php +++ b/uninstall.php @@ -22,21 +22,34 @@ /** * Function to delete all relevant data from the site (single or multisite). + * + * @param bool $is_multisite Whether it's a multisite installation. */ function dt_delete_data( $is_multisite = false ) { global $wpdb; // Delete post meta and posts of type 'dt_subscription'. - $subscription_post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'dt_subscription';" ); + $subscription_post_ids = $wpdb->get_col( + "SELECT ID FROM $wpdb->posts WHERE post_type = %s", + 'dt_subscription' + ); if ( ! empty( $subscription_post_ids ) ) { $ids_string = implode( ',', array_map( 'intval', $subscription_post_ids ) ); // Delete subscription meta. - $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids_string);" ); + $wpdb->query( + $wpdb->prepare( + "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids_string);" + ) + ); // Delete subscription posts. - $wpdb->query( "DELETE FROM $wpdb->posts WHERE ID IN ($ids_string);" ); + $wpdb->query( + $wpdb->prepare( + "DELETE FROM $wpdb->posts WHERE ID IN ($ids_string);" + ) + ); // Clear the post cache. wp_cache_set_posts_last_changed(); @@ -50,6 +63,8 @@ function dt_delete_data( $is_multisite = false ) { /** * Delete all relevant options from a site (single or multisite). + * + * @param bool $is_multisite Whether it's a multisite installation. */ function delete_site_options( $is_multisite = false ) { global $wpdb; @@ -60,22 +75,19 @@ function delete_site_options( $is_multisite = false ) { '_transient_timeout_dt_', ); - // Include multisite-specific prefixes if not a single site. - if ( ! $is_multisite ) { - $option_prefixes[] = '_site_transient_dt_'; - $option_prefixes[] = '_site_transient_timeout_dt_'; - } - - // Determine the appropriate table and column based on multisite or single site. + // Include multisite-specific prefixes if it's not a single site. + // Also determine the appropriate table and column based on multisite or single site. if ( $is_multisite ) { - $table = $wpdb->sitemeta; - $id_column = 'meta_id'; + $option_prefixes[] = '_site_transient_dt_'; + $option_prefixes[] = '_site_transient_timeout_dt_'; + $table = $wpdb->sitemeta; + $id_column = 'meta_id'; $key_column = 'meta_key'; $site_column = 'site_id'; - $site_id = get_current_network_id(); + $site_id = get_current_network_id(); } else { - $table = $wpdb->options; - $id_column = 'option_id'; + $table = $wpdb->options; + $id_column = 'option_id'; $key_column = 'option_name'; } @@ -104,7 +116,11 @@ function delete_site_options( $is_multisite = false ) { $ids_string = implode( ',', array_map( 'intval', $options_to_delete ) ); // Delete the options using the retrieved IDs. - $wpdb->query( "DELETE FROM $table WHERE $id_column IN ($ids_string);" ); + $wpdb->query( + $wpdb->prepare( + "DELETE FROM $table WHERE $id_column IN ($ids_string);" + ) + ); // Flush the relevant caches. $cache_group = $is_multisite ? 'site-options' : 'options'; From b96e12a894edc916b93d3d6893922f22f5d93754 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 5 Sep 2024 17:26:39 +0530 Subject: [PATCH 35/44] coding standards --- uninstall.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/uninstall.php b/uninstall.php index a0893594d..b0f5de16e 100644 --- a/uninstall.php +++ b/uninstall.php @@ -30,8 +30,10 @@ function dt_delete_data( $is_multisite = false ) { // Delete post meta and posts of type 'dt_subscription'. $subscription_post_ids = $wpdb->get_col( - "SELECT ID FROM $wpdb->posts WHERE post_type = %s", - 'dt_subscription' + $wpdb->prepare( + "SELECT ID FROM $wpdb->posts WHERE post_type = %s", + 'dt_subscription' + ) ); if ( ! empty( $subscription_post_ids ) ) { @@ -39,15 +41,17 @@ function dt_delete_data( $is_multisite = false ) { // Delete subscription meta. $wpdb->query( - $wpdb->prepare( - "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids_string);" + sprintf( + "DELETE FROM $wpdb->postmeta WHERE post_id IN (%s);", + $ids_string ) ); // Delete subscription posts. $wpdb->query( - $wpdb->prepare( - "DELETE FROM $wpdb->posts WHERE ID IN ($ids_string);" + sprintf( + "DELETE FROM $wpdb->posts WHERE ID IN (%s);", + $ids_string ) ); @@ -80,11 +84,11 @@ function delete_site_options( $is_multisite = false ) { if ( $is_multisite ) { $option_prefixes[] = '_site_transient_dt_'; $option_prefixes[] = '_site_transient_timeout_dt_'; - $table = $wpdb->sitemeta; - $id_column = 'meta_id'; - $key_column = 'meta_key'; + $table = $wpdb->sitemeta; + $id_column = 'meta_id'; + $key_column = 'meta_key'; $site_column = 'site_id'; - $site_id = get_current_network_id(); + $site_id = get_current_network_id(); } else { $table = $wpdb->options; $id_column = 'option_id'; @@ -97,13 +101,19 @@ function delete_site_options( $is_multisite = false ) { // Prepare the query with proper escaping for both single and multisite. $query = $is_multisite ? $wpdb->prepare( - "SELECT $id_column FROM $table WHERE $site_column = %d AND ($where_clause);", + sprintf( + "SELECT $id_column FROM $table WHERE $site_column = %%d AND (%s);", + $where_clause + ), array_merge( [ $site_id ], array_map( function( $prefix ) use ( $wpdb ) { return $wpdb->esc_like( $prefix ) . '%'; }, $option_prefixes ) ) ) : $wpdb->prepare( - "SELECT $id_column FROM $table WHERE $where_clause;", + sprintf( + "SELECT $id_column FROM $table WHERE %s;", + $where_clause + ), array_map( function( $prefix ) use ( $wpdb ) { return $wpdb->esc_like( $prefix ) . '%'; }, $option_prefixes ) @@ -117,8 +127,9 @@ function delete_site_options( $is_multisite = false ) { // Delete the options using the retrieved IDs. $wpdb->query( - $wpdb->prepare( - "DELETE FROM $table WHERE $id_column IN ($ids_string);" + sprintf( + "DELETE FROM $table WHERE $id_column IN (%s);", + $ids_string ) ); From ef103dd270087318a387f82e947324ff2afbad26 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 5 Sep 2024 17:52:47 +0530 Subject: [PATCH 36/44] add semicolon to help non-tech users --- includes/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 5841bad0f..36bf3cae9 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -240,7 +240,7 @@ static function () { '', esc_html__( 'Would you like to delete all Distributor data?', 'distributor' ), esc_html__( 'By default, the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well, add the code below to wp-config.php:', 'distributor' ), - 'define( \'DT_REMOVE_ALL_DATA\', true )', + 'define( \'DT_REMOVE_ALL_DATA\', true );', esc_html__( 'After adding this code, the Distributor plugin data will be removed from the website database when deleting the plugin. This will not delete the posts with their metadata other than the subscription. You can review uninstall.php (in the plugin root directory) to learn more about the deleted data. After deleting the Distributor plugin, you can remove the code from the wp-config.php file. Please make sure that this action cannot be undone; take a backup before proceeding.', 'distributor' ) ); } From 7826ef2fdc5e47ccc5caed5131de42841d090b99 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 5 Sep 2024 18:24:56 +0530 Subject: [PATCH 37/44] fix the issue - options are not deleting in multisite network --- uninstall.php | 143 +++++++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 66 deletions(-) diff --git a/uninstall.php b/uninstall.php index b0f5de16e..376037d91 100644 --- a/uninstall.php +++ b/uninstall.php @@ -21,11 +21,9 @@ global $wpdb; /** - * Function to delete all relevant data from the site (single or multisite). - * - * @param bool $is_multisite Whether it's a multisite installation. + * Function to delete all relevant data from the site. */ - function dt_delete_data( $is_multisite = false ) { + function dt_delete_data() { global $wpdb; // Delete post meta and posts of type 'dt_subscription'. @@ -41,17 +39,15 @@ function dt_delete_data( $is_multisite = false ) { // Delete subscription meta. $wpdb->query( - sprintf( - "DELETE FROM $wpdb->postmeta WHERE post_id IN (%s);", - $ids_string + $wpdb->prepare( + "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids_string)" ) ); // Delete subscription posts. $wpdb->query( - sprintf( - "DELETE FROM $wpdb->posts WHERE ID IN (%s);", - $ids_string + $wpdb->prepare( + "DELETE FROM $wpdb->posts WHERE ID IN ($ids_string)" ) ); @@ -61,16 +57,14 @@ function dt_delete_data( $is_multisite = false ) { wp_cache_delete_multiple( $subscription_post_ids, 'post_meta' ); } - // Delete relevant options (single or multisite). - delete_site_options( $is_multisite ); + // Delete relevant options from the options table. + delete_site_options(); } /** - * Delete all relevant options from a site (single or multisite). - * - * @param bool $is_multisite Whether it's a multisite installation. + * Delete all relevant options from the options table. */ - function delete_site_options( $is_multisite = false ) { + function delete_site_options() { global $wpdb; $option_prefixes = array( @@ -79,45 +73,18 @@ function delete_site_options( $is_multisite = false ) { '_transient_timeout_dt_', ); - // Include multisite-specific prefixes if it's not a single site. - // Also determine the appropriate table and column based on multisite or single site. - if ( $is_multisite ) { - $option_prefixes[] = '_site_transient_dt_'; - $option_prefixes[] = '_site_transient_timeout_dt_'; - $table = $wpdb->sitemeta; - $id_column = 'meta_id'; - $key_column = 'meta_key'; - $site_column = 'site_id'; - $site_id = get_current_network_id(); - } else { - $table = $wpdb->options; - $id_column = 'option_id'; - $key_column = 'option_name'; - } - - // Construct the WHERE clause based on the environment. - $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), "$key_column LIKE %s" ) ); - - // Prepare the query with proper escaping for both single and multisite. - $query = $is_multisite - ? $wpdb->prepare( - sprintf( - "SELECT $id_column FROM $table WHERE $site_column = %%d AND (%s);", - $where_clause - ), - array_merge( [ $site_id ], array_map( function( $prefix ) use ( $wpdb ) { - return $wpdb->esc_like( $prefix ) . '%'; - }, $option_prefixes ) ) - ) - : $wpdb->prepare( - sprintf( - "SELECT $id_column FROM $table WHERE %s;", - $where_clause - ), - array_map( function( $prefix ) use ( $wpdb ) { - return $wpdb->esc_like( $prefix ) . '%'; - }, $option_prefixes ) - ); + // Prepare the WHERE clause for the options table. + $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), "option_name LIKE %s" ) ); + + $query = $wpdb->prepare( + sprintf( + "SELECT option_id FROM $wpdb->options WHERE %s;", + $where_clause + ), + array_map( function( $prefix ) use ( $wpdb ) { + return $wpdb->esc_like( $prefix ) . '%'; + }, $option_prefixes ) + ); // Fetch the options to delete. $options_to_delete = $wpdb->get_col( $query ); @@ -127,20 +94,61 @@ function delete_site_options( $is_multisite = false ) { // Delete the options using the retrieved IDs. $wpdb->query( - sprintf( - "DELETE FROM $table WHERE $id_column IN (%s);", - $ids_string + $wpdb->prepare( + "DELETE FROM $wpdb->options WHERE option_id IN ($ids_string)" ) ); - // Flush the relevant caches. - $cache_group = $is_multisite ? 'site-options' : 'options'; - wp_cache_delete_multiple( $options_to_delete, $cache_group ); + // Flush the options cache. + wp_cache_delete_multiple( $options_to_delete, 'options' ); - if ( ! $is_multisite ) { - // Flush the alloptions cache if it's a single site. - wp_cache_delete( 'alloptions', 'options' ); - } + // Flush the alloptions cache. + wp_cache_delete( 'alloptions', 'options' ); + } + } + + /** + * Delete all relevant options from the sitemeta table (multisite only). + */ + function delete_sitemeta_options() { + global $wpdb; + + $option_prefixes = array( + 'dt_', + '_site_transient_dt_', + '_site_transient_timeout_dt_', + ); + + // Prepare the WHERE clause for the sitemeta table. + $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), "meta_key LIKE %s" ) ); + + $site_id = get_current_network_id(); + + $query = $wpdb->prepare( + sprintf( + "SELECT meta_id FROM $wpdb->sitemeta WHERE site_id = %%d AND (%s);", + $where_clause + ), + array_merge( [ $site_id ], array_map( function( $prefix ) use ( $wpdb ) { + return $wpdb->esc_like( $prefix ) . '%'; + }, $option_prefixes ) ) + ); + + // Fetch the sitemeta to delete. + $sitemeta_to_delete = $wpdb->get_col( $query ); + + if ( ! empty( $sitemeta_to_delete ) ) { + $ids_string = implode( ',', array_map( 'intval', $sitemeta_to_delete ) ); + + // Delete the sitemeta using the retrieved IDs. + $wpdb->query( + $wpdb->prepare( + "DELETE FROM $wpdb->sitemeta WHERE meta_id IN ($ids_string)" + ) + ); + + // Flush the site options cache. + wp_cache_delete_multiple( $sitemeta_to_delete, 'site-options' ); } } @@ -150,9 +158,12 @@ function delete_site_options( $is_multisite = false ) { $sites = get_sites(); foreach ( $sites as $site ) { switch_to_blog( $site->blog_id ); - dt_delete_data( true ); + dt_delete_data(); restore_current_blog(); } + + // Delete network-wide sitemeta options. + delete_sitemeta_options(); } else { // Single site. dt_delete_data(); From 692323732cc572969a880d85d9d864cbdf132cc4 Mon Sep 17 00:00:00 2001 From: Faisal Alvi Date: Fri, 6 Sep 2024 19:27:29 +0530 Subject: [PATCH 38/44] Apply suggestions from code review Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> --- includes/bootstrap.php | 12 ++++++------ uninstall.php | 6 +----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 36bf3cae9..e7dd98e92 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -246,27 +246,27 @@ static function () { } ); - $modal_title = esc_js( esc_html__( 'Distributor Deactivation', 'distributor' ) ); - $modal_button_title_deactivate = esc_js( esc_html__( 'Deactivate', 'distributor' ) ); - $modal_button_title_cancel = esc_js( esc_html__( 'Cancel', 'distributor' ) ); + $modal_title = wp_json_encode( __( 'Distributor Deactivation', 'distributor' ) ); + $modal_button_title_deactivate = wp_json_encode( __( 'Deactivate', 'distributor' ) ); + $modal_button_title_cancel = wp_json_encode( __( 'Cancel', 'distributor' ) ); $script = <<query( - $wpdb->prepare( - "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids_string)" - ) + "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids_string)" ); // Delete subscription posts. @@ -170,4 +167,3 @@ function delete_sitemeta_options() { } } -// phpcs:enable From 15e060dc1044333af9367cf3b3c6c6d8ba9dd4fa Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Fri, 13 Sep 2024 20:04:17 +0530 Subject: [PATCH 39/44] pass `option_name` in `wp_cache_delete_multiple` for `options` --- uninstall.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/uninstall.php b/uninstall.php index 23f71fa5c..b1b01b85a 100644 --- a/uninstall.php +++ b/uninstall.php @@ -73,9 +73,10 @@ function delete_site_options() { // Prepare the WHERE clause for the options table. $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), "option_name LIKE %s" ) ); + // Prepare the query. $query = $wpdb->prepare( sprintf( - "SELECT option_id FROM $wpdb->options WHERE %s;", + "SELECT option_id, option_name FROM $wpdb->options WHERE %s;", $where_clause ), array_map( function( $prefix ) use ( $wpdb ) { @@ -84,10 +85,12 @@ function delete_site_options() { ); // Fetch the options to delete. - $options_to_delete = $wpdb->get_col( $query ); + $options_to_delete = $wpdb->get_results( $query, ARRAY_A ); if ( ! empty( $options_to_delete ) ) { - $ids_string = implode( ',', array_map( 'intval', $options_to_delete ) ); + // Collect IDs from fetched options. + $ids = array_column( $options_to_delete, 'option_id' ); + $ids_string = implode( ',', array_map( 'intval', $ids ) ); // Delete the options using the retrieved IDs. $wpdb->query( @@ -97,7 +100,8 @@ function delete_site_options() { ); // Flush the options cache. - wp_cache_delete_multiple( $options_to_delete, 'options' ); + $option_names = array_column( $options_to_delete, 'option_name' ); + wp_cache_delete_multiple( $option_names, 'options' ); // Flush the alloptions cache. wp_cache_delete( 'alloptions', 'options' ); From 39830c6d946e984dee70328cbb4fec43ee4b4852 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Fri, 13 Sep 2024 20:05:10 +0530 Subject: [PATCH 40/44] pass `site_id:meta_key` in `wp_cache_delete_multiple` for `site-options` --- uninstall.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/uninstall.php b/uninstall.php index b1b01b85a..018721c91 100644 --- a/uninstall.php +++ b/uninstall.php @@ -127,7 +127,7 @@ function delete_sitemeta_options() { $query = $wpdb->prepare( sprintf( - "SELECT meta_id FROM $wpdb->sitemeta WHERE site_id = %%d AND (%s);", + "SELECT meta_id, meta_key FROM $wpdb->sitemeta WHERE site_id = %%d AND (%s);", $where_clause ), array_merge( [ $site_id ], array_map( function( $prefix ) use ( $wpdb ) { @@ -136,10 +136,12 @@ function delete_sitemeta_options() { ); // Fetch the sitemeta to delete. - $sitemeta_to_delete = $wpdb->get_col( $query ); + $sitemeta_to_delete = $wpdb->get_results( $query, ARRAY_A ); if ( ! empty( $sitemeta_to_delete ) ) { - $ids_string = implode( ',', array_map( 'intval', $sitemeta_to_delete ) ); + // Collect IDs from fetched options. + $ids = array_column( $sitemeta_to_delete, 'meta_id' ); + $ids_string = implode( ',', array_map( 'intval', $ids ) ); // Delete the sitemeta using the retrieved IDs. $wpdb->query( @@ -149,7 +151,11 @@ function delete_sitemeta_options() { ); // Flush the site options cache. - wp_cache_delete_multiple( $sitemeta_to_delete, 'site-options' ); + $key_names = array_column( $sitemeta_to_delete, 'meta_key' ); + $key_names = array_map( function( $key ) use ( $site_id ) { + return $site_id . ':' . $key; + }, $key_names ); + wp_cache_delete_multiple( $key_names, 'site-options' ); } } From 548c8a175042f6ea524ed301de18514ed0b2c692 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Fri, 13 Sep 2024 20:05:34 +0530 Subject: [PATCH 41/44] include site transient keys to delete --- uninstall.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/uninstall.php b/uninstall.php index 018721c91..b01851ef1 100644 --- a/uninstall.php +++ b/uninstall.php @@ -70,6 +70,16 @@ function delete_site_options() { '_transient_timeout_dt_', ); + if ( is_multisite() ) { + $option_prefixes = array_merge( + $option_prefixes, + array( + '_site_transient_dt_', + '_site_transient_timeout_dt_', + ) + ); + } + // Prepare the WHERE clause for the options table. $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), "option_name LIKE %s" ) ); From 2aa68dfbd64aabb06ded8c84fc4a40b7c0b73a79 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Fri, 13 Sep 2024 20:18:42 +0530 Subject: [PATCH 42/44] phpcs: fixes and ignores --- uninstall.php | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/uninstall.php b/uninstall.php index b01851ef1..9b2e00b7c 100644 --- a/uninstall.php +++ b/uninstall.php @@ -6,6 +6,7 @@ * @since x.x.x */ + // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { die; @@ -44,7 +45,8 @@ function dt_delete_data() { // Delete subscription posts. $wpdb->query( $wpdb->prepare( - "DELETE FROM $wpdb->posts WHERE ID IN ($ids_string)" + "DELETE FROM $wpdb->posts WHERE ID IN (%s)", + $ids_string ) ); @@ -81,7 +83,7 @@ function delete_site_options() { } // Prepare the WHERE clause for the options table. - $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), "option_name LIKE %s" ) ); + $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), 'option_name LIKE %s' ) ); // Prepare the query. $query = $wpdb->prepare( @@ -89,9 +91,12 @@ function delete_site_options() { "SELECT option_id, option_name FROM $wpdb->options WHERE %s;", $where_clause ), - array_map( function( $prefix ) use ( $wpdb ) { - return $wpdb->esc_like( $prefix ) . '%'; - }, $option_prefixes ) + array_map( + function( $prefix ) use ( $wpdb ) { + return $wpdb->esc_like( $prefix ) . '%'; + }, + $option_prefixes + ) ); // Fetch the options to delete. @@ -131,7 +136,7 @@ function delete_sitemeta_options() { ); // Prepare the WHERE clause for the sitemeta table. - $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), "meta_key LIKE %s" ) ); + $where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), 'meta_key LIKE %s' ) ); $site_id = get_current_network_id(); @@ -140,9 +145,15 @@ function delete_sitemeta_options() { "SELECT meta_id, meta_key FROM $wpdb->sitemeta WHERE site_id = %%d AND (%s);", $where_clause ), - array_merge( [ $site_id ], array_map( function( $prefix ) use ( $wpdb ) { - return $wpdb->esc_like( $prefix ) . '%'; - }, $option_prefixes ) ) + array_merge( + [ $site_id ], + array_map( + function( $prefix ) use ( $wpdb ) { + return $wpdb->esc_like( $prefix ) . '%'; + }, + $option_prefixes + ) + ) ); // Fetch the sitemeta to delete. @@ -162,9 +173,12 @@ function delete_sitemeta_options() { // Flush the site options cache. $key_names = array_column( $sitemeta_to_delete, 'meta_key' ); - $key_names = array_map( function( $key ) use ( $site_id ) { - return $site_id . ':' . $key; - }, $key_names ); + $key_names = array_map( + function( $key ) use ( $site_id ) { + return $site_id . ':' . $key; + }, + $key_names + ); wp_cache_delete_multiple( $key_names, 'site-options' ); } } From 8444087cc6ee328f55cbe9f83e4c459bd403a1f1 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Mon, 16 Sep 2024 21:32:06 +0530 Subject: [PATCH 43/44] Site transients can be used on single sites too. --- uninstall.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index 9b2e00b7c..9c510446c 100644 --- a/uninstall.php +++ b/uninstall.php @@ -72,7 +72,9 @@ function delete_site_options() { '_transient_timeout_dt_', ); - if ( is_multisite() ) { + // Site transients can be used on single sites too. + // See https://github.com/10up/distributor/pull/540#discussion_r1759587692 + if ( ! is_multisite() ) { $option_prefixes = array_merge( $option_prefixes, array( From a46f0b5a1710e72fc89d1ee862b10abf004c4e96 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Wed, 16 Oct 2024 21:13:01 +0530 Subject: [PATCH 44/44] include uninstall.php to release version --- webpack.config.release.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webpack.config.release.js b/webpack.config.release.js index 98edf3b98..757689ce4 100644 --- a/webpack.config.release.js +++ b/webpack.config.release.js @@ -10,6 +10,7 @@ module.exports = { new CopyPlugin( { patterns: [ { from: 'readme.txt', to: './' }, + { from: 'uninstall.php', to: './' }, { from: 'README.md', to: './' }, { from: 'CHANGELOG.md', to: './' }, { from: 'composer.json', to: './' },