forked from hizzle-co/noptin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
48 lines (39 loc) · 1.04 KB
/
uninstall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
// Delete the actions page.
$page = get_option( 'noptin_actions_page' );
if ( is_numeric( $page ) ) {
wp_delete_post( $page, true );
}
// Delete options.
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'noptin\_%';" );
// Delete tables.
$tables = array(
"{$wpdb->prefix}noptin_subscribers",
"{$wpdb->prefix}noptin_subscriber_meta",
"{$wpdb->prefix}noptin_automation_rules",
);
foreach ( $tables as $table ) {
$wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}
// Delete newsletters.
$wpdb->query(
"DELETE a,b
FROM {$wpdb->posts} a
LEFT JOIN {$wpdb->postmeta} b
ON (a.ID = b.post_id)
WHERE a.post_type = 'noptin-campaign'"
);
// Delete subscription forms.
$wpdb->query(
"DELETE a,b
FROM {$wpdb->posts} a
LEFT JOIN {$wpdb->postmeta} b
ON (a.ID = b.post_id)
WHERE a.post_type = 'noptin-form'"
);
// Crons.
wp_clear_scheduled_hook( 'noptin_daily_maintenance' );