Repository navigation
Expand file tree
/
Copy pathuninstall.php
More file actions
64 lines (55 loc) · 2.06 KB
/
Copy pathuninstall.php
File metadata and controls
64 lines (55 loc) · 2.06 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
<?php
declare(strict_types=1);
if (! defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
global $wpdb;
// Remove all field data stored in post, term, user and comment meta.
$wpdb->delete($wpdb->postmeta, ['meta_key' => '_ctrlfield_data']);
$wpdb->delete($wpdb->termmeta, ['meta_key' => '_ctrlfield_data']);
$wpdb->delete($wpdb->usermeta, ['meta_key' => '_ctrlfield_data']);
$wpdb->delete($wpdb->commentmeta, ['meta_key' => '_ctrlfield_data']);
// Remove all indexed meta keys (_ctrlfield_idx_*).
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s",
$wpdb->esc_like('_ctrlfield_idx_') . '%'
)
);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->termmeta} WHERE meta_key LIKE %s",
$wpdb->esc_like('_ctrlfield_idx_') . '%'
)
);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s",
$wpdb->esc_like('_ctrlfield_idx_') . '%'
)
);
// Remove options page data (_ctrlfield_options_*).
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$wpdb->esc_like('_ctrlfield_options_') . '%'
)
);
// Pro: license and webhook options (and the removed audit log's flag).
delete_option('_ctrlfield_pro_license_key');
delete_option('_ctrlfield_pro_instance_id');
delete_option('_ctrlfield_pro_license_cache');
delete_option('_ctrlfield_pro_webhook_secret');
delete_option('_ctrlf_pro_audit_log_db_version');
wp_clear_scheduled_hook('ctrlfield_pro_weekly_purge');
// Pro: drop all tables created by CtrlField (CCT tables, and the removed audit log's).
// Table names come from the DB itself (not user input), but we validate format before use.
$ctrlf_prefix = $wpdb->prefix . 'ctrlf_';
$tables = $wpdb->get_col(
$wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($ctrlf_prefix) . '%')
);
foreach ($tables as $table) {
if (is_string($table) && preg_match('/^[a-zA-Z0-9_$]+$/', $table)) {
$wpdb->query("DROP TABLE IF EXISTS `{$table}`"); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
}