Skip to content

Commit 365cc35

Browse files
delete all plugin data when plugin is uninstalled / fully deleted. closes #524
1 parent dc21a2f commit 365cc35

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

mailchimp-for-wp.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ function _mc4wp_load_plugin()
100100
require __DIR__ . '/integrations/bootstrap.php';
101101
}
102102

103-
function _mc4wp_on_plugin_activation()
104-
{
105-
// schedule the action hook to refresh the stored Mailchimp lists on a daily basis
106-
$time_string = sprintf('tomorrow %d:%d am', rand(0, 7), rand(0, 59));
107-
wp_schedule_event(strtotime($time_string), 'daily', 'mc4wp_refresh_mailchimp_lists');
108-
}
109-
110-
111103
// bootstrap main plugin
112104
add_action('plugins_loaded', '_mc4wp_load_plugin', 8);
113105

114-
register_activation_hook(__FILE__, '_mc4wp_on_plugin_activation');
106+
// schedule the action hook to refresh the stored Mailchimp lists on a daily basis
107+
register_activation_hook(__FILE__, function() {
108+
$time_string = sprintf('tomorrow %d:%d am', rand(0, 7), rand(0, 59));
109+
wp_schedule_event(strtotime($time_string), 'daily', 'mc4wp_refresh_mailchimp_lists');
110+
});
111+
112+
// remove scheduled hook when plugin is deactivated
113+
register_deactivation_hook(__FILE__, function() {
114+
wp_clear_scheduled_hook('mc4wp_refresh_mailchimp_lists');
115+
});

uninstall.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
// if uninstall.php is not called by WordPress, die
4+
if (!defined('WP_UNINSTALL_PLUGIN')) die;
5+
6+
global $wpdb;
7+
8+
// Delete all MC4WP related options and transients
9+
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name = 'mc4wp' OR option_name LIKE 'mc4wp%' OR option_name LIKE '_transient_mc4wp_%' OR option_name LIKE '_transient_timeout_mc4wp_%';");
10+
11+
// Delete all MC4WP forms + settings
12+
$wpdb->query("DELETE p, pm FROM {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID WHERE p.post_type = 'mc4wp-form';");

0 commit comments

Comments
 (0)