-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
67 lines (57 loc) · 1.96 KB
/
Copy pathuninstall.php
File metadata and controls
67 lines (57 loc) · 1.96 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
<?php
/**
* Uninstall script for PDF Invoice Generator for MemberPress
*
* This script runs when the plugin is deleted from WordPress.
* It cleans up all plugin data, options, and generated files.
*/
// If uninstall not called from WordPress, exit
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Check if we should clean up files
$cleanup_files = get_option( 'mpfig_cleanup_files_on_uninstall', true );
if ( $cleanup_files ) {
// Clean up generated PDF files
$upload_dir = wp_upload_dir();
$pdf_dir = $upload_dir['basedir'] . '/mepr/mpdf/';
if ( is_dir( $pdf_dir ) ) {
// Get all PDF and ZIP files created by this plugin
$files = array_merge(
glob( $pdf_dir . '*.pdf' ),
glob( $pdf_dir . 'memberpress-invoices-*.zip' )
);
foreach ( $files as $file ) {
if ( is_file( $file ) ) {
wp_delete_file( $file );
}
}
// Remove the directory if it's empty using WP_Filesystem
if ( ! function_exists( 'WP_Filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
$access_type = get_filesystem_method();
if ( 'direct' === $access_type ) {
$creds = request_filesystem_credentials( site_url() . '/wp-admin/', '', false, false, array() );
if ( WP_Filesystem( $creds ) ) {
global $wp_filesystem;
if ( count( glob( $pdf_dir . '*' ) ) === 0 ) {
$wp_filesystem->rmdir( $pdf_dir );
}
}
}
}
}
// Clean up plugin options
$options_to_delete = array(
'mpfig_progress',
'mpfig_cleanup_files_on_uninstall',
'mpfig_last_generation_time',
'mpfig_generation_stats'
);
foreach ( $options_to_delete as $option ) {
delete_option( $option );
}
// Clean up any transients
delete_transient( 'mpfig_progress_data' );
delete_transient( 'mpfig_generation_status' );