Skip to content

Commit

Permalink
delete all plugin data when plugin is uninstalled / fully deleted. cl…
Browse files Browse the repository at this point in the history
…oses #524
  • Loading branch information
dannyvankooten committed Jan 8, 2025
1 parent dc21a2f commit 365cc35
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 10 additions & 9 deletions mailchimp-for-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ function _mc4wp_load_plugin()
require __DIR__ . '/integrations/bootstrap.php';
}

function _mc4wp_on_plugin_activation()
{
// schedule the action hook to refresh the stored Mailchimp lists on a daily basis
$time_string = sprintf('tomorrow %d:%d am', rand(0, 7), rand(0, 59));
wp_schedule_event(strtotime($time_string), 'daily', 'mc4wp_refresh_mailchimp_lists');
}


// bootstrap main plugin
add_action('plugins_loaded', '_mc4wp_load_plugin', 8);

register_activation_hook(__FILE__, '_mc4wp_on_plugin_activation');
// schedule the action hook to refresh the stored Mailchimp lists on a daily basis
register_activation_hook(__FILE__, function() {
$time_string = sprintf('tomorrow %d:%d am', rand(0, 7), rand(0, 59));
wp_schedule_event(strtotime($time_string), 'daily', 'mc4wp_refresh_mailchimp_lists');
});

// remove scheduled hook when plugin is deactivated
register_deactivation_hook(__FILE__, function() {
wp_clear_scheduled_hook('mc4wp_refresh_mailchimp_lists');
});
12 changes: 12 additions & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

// if uninstall.php is not called by WordPress, die
if (!defined('WP_UNINSTALL_PLUGIN')) die;

global $wpdb;

// Delete all MC4WP related options and transients
$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_%';");

// Delete all MC4WP forms + settings
$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 comments on commit 365cc35

Please sign in to comment.