-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
91 lines (70 loc) · 2.21 KB
/
Copy pathuninstall.php
File metadata and controls
91 lines (70 loc) · 2.21 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
<?php
/**
* Uninstall
*
* @package AllFeedback
*/
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
require_once ABSPATH . 'wp-admin/includes/file.php';
// ------------------------------------------------------------------
// Guard: only wipe data when the admin explicitly opted in.
// Read directly from wp_options — no plugin classes are available here.
// ------------------------------------------------------------------
$allfeedback_settings = get_option( '_allfeedback_settings', [] );
$allfeedback_delete = isset( $allfeedback_settings['advanced']['plugin']['delete_on_uninstall'] )
? (bool) $allfeedback_settings['advanced']['plugin']['delete_on_uninstall']
: false;
if ( ! $allfeedback_delete ) {
return;
}
global $wpdb;
$allfeedback_tables = [
$wpdb->prefix . 'af_responses',
$wpdb->prefix . 'af_survey_sessions',
$wpdb->prefix . 'af_surveys',
$wpdb->prefix . 'af_migrations',
];
foreach ( $allfeedback_tables as $allfeedback_table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$allfeedback_table}" );
}
$allfeedback_options = [
'_allfeedback_migrations',
'_allfeedback_settings',
'_allfeedback_features',
'_allfeedback_enabled_modules',
'_allfeedback_wizard_data',
'allfeedback_rewrite_version',
'allfeedback_wizard_status',
];
foreach ( $allfeedback_options as $allfeedback_option ) {
delete_option( $allfeedback_option );
}
$allfeedback_uploads_dir = wp_upload_dir()['basedir'] . '/allfeedback';
allfeedback_delete_directory( $allfeedback_uploads_dir );
/**
* Recursively delete a directory and everything inside it.
*
* @param string $dir Absolute path to the directory.
*/
function allfeedback_delete_directory( string $dir ): void {
global $wp_filesystem;
if ( ! is_dir( $dir ) ) {
return;
}
if ( ! WP_Filesystem() || ! $wp_filesystem ) {
return;
}
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS ),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ( $iterator as $file ) {
if ( $file->isDir() ) {
$wp_filesystem->rmdir( $file->getRealPath(), false );
} else {
wp_delete_file( $file->getRealPath() );
}
}
$wp_filesystem->rmdir( $dir, false );
}