-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
97 lines (87 loc) · 2.83 KB
/
uninstall.php
File metadata and controls
97 lines (87 loc) · 2.83 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
89
90
91
92
93
94
95
96
97
<?php
/**
* Bazaar uninstall — runs when the plugin is deleted from the WordPress admin.
*
* Removes ALL plugin data:
* - bazaar_registry option
* - bazaar_max_ware_size option
* - wp-content/bazaar/ directory and all installed wares
*
* Deactivation intentionally leaves everything intact so re-activating the
* plugin restores the previous state. Uninstall (delete) is the destructive
* action and only runs when the user explicitly clicks "Delete" in wp-admin.
*
* @package Bazaar
*/
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
global $wpdb;
// Remove all scalar options.
$_bazaar_options = array(
'bazaar_index',
'bazaar_registry',
'bazaar_max_ware_size',
'bazaar_secret',
'bazaar_registry_url',
'bazaar_signing_pubkey',
'bazaar_enforce_signatures',
'bazaar_last_update_check',
'bazaar_outdated_wares',
'bazaar_site_overrides',
'bazaar_webhooks',
'bazaar_csp_policy',
'bazaar_analytics_enabled',
);
foreach ( $_bazaar_options as $_opt ) {
delete_option( $_opt );
}
// Remove all per-ware options (bazaar_ware_{slug}).
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$wpdb->esc_like( 'bazaar_ware_' ) . '%'
)
);
// Remove all per-ware options (bazaar_ware_{slug}, bazaar_license_{slug}, bazaar_badges_{uid}).
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
$wpdb->esc_like( 'bazaar_ware_' ) . '%',
$wpdb->esc_like( 'bazaar_license_' ) . '%'
)
);
// Remove per-user badge transients.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_bazaar_badges_' ) . '%'
)
);
// Drop all custom tables.
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}bazaar_analytics" );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}bazaar_errors" );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}bazaar_audit_log" );
// phpcs:enable
// Unschedule all Bazaar cron jobs.
foreach ( array( 'bazaar_check_updates', 'bazaar_health_refresh' ) as $_hook ) {
$_ts = wp_next_scheduled( $_hook );
if ( $_ts ) {
wp_unschedule_event( $_ts, $_hook );
}
}
// Remove wp-content/bazaar/ and all installed wares.
$wares_dir = WP_CONTENT_DIR . '/bazaar/';
if ( is_dir( $wares_dir ) ) {
if ( ! function_exists( 'WP_Filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
WP_Filesystem();
global $wp_filesystem;
if ( ! empty( $wp_filesystem ) ) {
$wp_filesystem->delete( $wares_dir, true );
}
}