-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
63 lines (53 loc) · 1.72 KB
/
uninstall.php
File metadata and controls
63 lines (53 loc) · 1.72 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
<?php
/**
* Uninstall handler for VMFA Folder Exporter.
*
* Fired when the plugin is deleted via the WordPress admin.
* Removes all plugin data: options, export files, and scheduled actions.
*
* @package VmfaFolderExporter
*/
// Exit if not called by WordPress.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
// Delete all export metadata options.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$option_names = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
$wpdb->esc_like( 'vmfa_export_' ) . '%'
)
);
foreach ( $option_names as $name ) {
$export = get_option( $name );
// Delete associated ZIP files.
if ( is_array( $export ) && ! empty( $export[ 'file_path' ] ) && file_exists( $export[ 'file_path' ] ) ) {
wp_delete_file( $export[ 'file_path' ] );
}
delete_option( $name );
}
// Remove the export directory.
$upload_dir = wp_upload_dir();
$default = $upload_dir[ 'basedir' ] . '/vmfa-exports';
/** This filter is documented in ExportService::get_export_dir(). */
$export_dir = apply_filters( 'vmfa_export_dir', $default );
if ( is_dir( $export_dir ) ) {
// Remove protection and remaining files.
$files = glob( $export_dir . '/*' );
if ( is_array( $files ) ) {
foreach ( $files as $file ) {
if ( is_file( $file ) ) {
wp_delete_file( $file );
}
}
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
rmdir( $export_dir );
}
// Unschedule Action Scheduler actions.
if ( function_exists( 'as_unschedule_all_actions' ) ) {
as_unschedule_all_actions( 'vmfa_folder_exporter_build' );
as_unschedule_all_actions( 'vmfa_folder_exporter_cleanup' );
}