-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
88 lines (78 loc) · 3.24 KB
/
uninstall.php
File metadata and controls
88 lines (78 loc) · 3.24 KB
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
<?php
/**
* Uninstall routine for kwtSMS: OTP & SMS Notifications.
*
* @package KwtSMS_OTP
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
/**
* Uninstall routine for kwtSMS: OTP & SMS Notifications.
*
* WordPress only runs this file when the plugin is deleted (not just deactivated).
* The WP_UNINSTALL_PLUGIN check is required — it prevents direct execution.
*
* Data removed:
* - All kwtsms_otp_* options from wp_options
* - All kwtsms_phone user meta from wp_usermeta
* - All kwtsms_otp_* and kwtsms_partial_auth_* transients
* - Scheduled cron events (kwtsms_check_abandoned_carts)
* - Debug log file (wp-content/kwtsms-debug.log)
*
* @package KwtSMS_OTP
*/
global $wpdb;
// -------------------------------------------------------------------------
// 1. Remove all plugin options.
// -------------------------------------------------------------------------
$kwtsms_options = array(
'kwtsms_otp_general',
'kwtsms_otp_gateway',
'kwtsms_otp_templates',
'kwtsms_otp_version',
'kwtsms_otp_send_log',
'kwtsms_otp_sms_history',
'kwtsms_otp_attempt_log',
'kwtsms_otp_integrations',
'kwtsms_otp_alerts',
'kwtsms_abandoned_carts',
);
foreach ( $kwtsms_options as $kwtsms_option ) {
delete_option( $kwtsms_option );
// Also remove from multisite if applicable.
delete_site_option( $kwtsms_option );
}
// -------------------------------------------------------------------------
// 2. Remove user phone meta.
// -------------------------------------------------------------------------
delete_metadata( 'user', 0, 'kwtsms_phone', '', true );
delete_metadata( 'user', 0, 'kwtsms_dismissed_version', '', true );
delete_metadata( 'user', 0, 'kwtsms_trusted_devices', '', true );
// -------------------------------------------------------------------------
// 3. Remove product post meta (back-in-stock subscribers).
// -------------------------------------------------------------------------
delete_post_meta_by_key( 'kwtsms_back_in_stock_subscribers' );
// -------------------------------------------------------------------------
// 4. Remove transients (OTPs, partial auths, rate limiters).
// Transients are stored as _transient_* and _transient_timeout_* in options.
// -------------------------------------------------------------------------
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
$wpdb->esc_like( '_transient_kwtsms_' ) . '%',
$wpdb->esc_like( '_transient_timeout_kwtsms_' ) . '%'
)
);
// -------------------------------------------------------------------------
// 5. Clear scheduled cron events.
// -------------------------------------------------------------------------
wp_clear_scheduled_hook( 'kwtsms_check_abandoned_carts' );
// -------------------------------------------------------------------------
// 6. Remove debug log file.
// -------------------------------------------------------------------------
$kwtsms_upload_dir = wp_upload_dir();
$kwtsms_debug_log = ! empty( $kwtsms_upload_dir['basedir'] ) ? $kwtsms_upload_dir['basedir'] . '/kwtsms-debug.log' : '';
if ( $kwtsms_debug_log && file_exists( $kwtsms_debug_log ) ) {
wp_delete_file( $kwtsms_debug_log );
}