-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
96 lines (74 loc) · 3.24 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
// if uninstall is not initiated by WordPress, do nothing
if( !defined( 'WP_UNINSTALL_PLUGIN' ) ) exit ();
// otherwise...
// delete options from options table
delete_option( 'dk_speakout_options' );
delete_option( 'dk_speakout_version' );
delete_option( 'dk_speakout_license_key' );
delete_option( 'dk_speakout_license_key_verified' );
//if they have dismissed banner, delete the meta
if( metadata_exists('user', get_current_user_id(), 'SpeakOut_plugin_notice_ignore' ) ){
delete_user_meta(get_current_user_id(), 'SpeakOut_plugin_notice_ignore' );
}
// set variables for accessing database
global $wpdb;
$db_petitions = $wpdb->prefix . "dk_speakout_petitions";
$db_signatures = $wpdb->prefix . "dk_speakout_signatures";
$db_options = $wpdb->prefix . "options";
// delete any remaining transients
// get ids for all existing petitions
$sql_petition_ids = "SELECT id FROM $db_petitions";
$petitions = $wpdb->get_results( $sql_petition_ids );
// loop through petitions and delete associated transients
foreach ( $petitions as $petition ) {
// construct transient names
$transient_petition = 'dk_speakout_petition_' . $petition->id;
$transient_signatureslist = 'dk_speakout_signatureslist_' . $petition->id;
$transient_signatures_total = 'dk_speakout_signatures_total_' . $petition->id;
// delete transients
delete_transient( $transient_petition );
delete_transient( $transient_signatureslist );
delete_transient( $transient_signatures_total );
}
//delete options data
$sql_options = "DELETE FROM $db_options WHERE option_name = 'dk_speakout_options'";
$wpdb->query( $sql_options );
// delete widget data
$sql_widget = "DELETE FROM $db_options WHERE option_name = 'widget_dk_speakout_petition_widget'";
$wpdb->query( $sql_widget );
// delete custom database tables
$sql_petitions_table = "DROP TABLE $db_petitions";
$wpdb->query( $sql_petitions_table );
$sql_signatures_table = "DROP TABLE $db_signatures";
$wpdb->query( $sql_signatures_table );
// delete WPML strings
if ( function_exists( 'icl_unregister_string' ) ) {
// delete petition strings in WPML
foreach ( $petitions as $petition ) {
$context = 'Petition ' . $petition->id;
icl_unregister_string( $context, 'petition title' );
icl_unregister_string( $context, 'email subject' );
icl_unregister_string( $context, 'greeting' );
icl_unregister_string( $context, 'petition message' );
icl_unregister_string( $context, 'custom field label' );
icl_unregister_string( $context, 'x message' );
icl_unregister_string( $context, 'optin label' );
}
// delete widget strings in WPML
foreach ( $petitions as $petition ) {
$context = 'Petition ' . $petition->id;
icl_unregister_string( $context, 'widget title' );
icl_unregister_string( $context, 'widget call to action' );
}
// delete options strings in WPML
icl_unregister_string( 'Petition', 'submit button text' );
icl_unregister_string( 'Petition', 'success message' );
icl_unregister_string( 'Petition', 'share message' );
icl_unregister_string( 'Petition', 'expiration message' );
icl_unregister_string( 'Petition', 'already signed message' );
icl_unregister_string( 'Petition', 'signaturelist title' );
icl_unregister_string( 'Petition', 'confirmation email subject' );
icl_unregister_string( 'Petition', 'confirmation email message' );
}
?>