-
Notifications
You must be signed in to change notification settings - Fork 17
/
uninstall.php
114 lines (92 loc) · 2.39 KB
/
uninstall.php
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* @since 3.0.0
*/
// phpcs:disable WordPress.DB.DirectDatabaseQuery
// if uninstall.php is not called by WordPress, die
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
die;
}
require_once 'jet-form-builder.php';
// Disable Action Schedule Queue Runner.
if ( class_exists( 'ActionScheduler_QueueRunner' ) ) {
ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request();
}
$options = get_option( 'jet_form_builder_settings__options-tab' );
if ( ! $options ) {
return;
}
$options = json_decode( $options, true );
if ( empty( $options['clear_on_uninstall'] ) ) {
return;
}
$opt_prefixes = array(
'jet\_form\_builder\_settings\_\_',
'jet\_fb\_',
'jfb\-',
'jfb\_',
);
$additional_prefixes = array();
foreach ( $opt_prefixes as $prefix ) {
array_push(
$additional_prefixes,
'\_transient\_' . $prefix,
'\_site\_transient\_' . $prefix,
'\_transient\_timeout\_' . $prefix,
'\_site\_transient\_timeout\_' . $prefix
);
}
$opt_prefixes = array_merge( $opt_prefixes, $additional_prefixes );
$options_condition = "option_name LIKE '" . implode( "%' OR option_name LIKE '", $opt_prefixes ) . "%'";
$tables = array(
// secondary tables
'tokens_to_records',
'records_actions',
'records_errors',
'records_fields',
'subscription_to_payer_shipping',
'subscriptions_to_records',
'subscriptions_to_payments',
'subscriptions_notes',
'payment_to_payer_shipping',
'payments_to_records',
'payers_shipping',
// primary tables
'tokens',
'csrf_tokens',
'recurring_cycles',
'subscriptions',
'payments',
'migrations',
'payers',
'records',
);
global $wpdb;
// phpcs:disable WordPress.DB.PreparedSQL
foreach ( $tables as $table_name ) {
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'jet_fb_' . $table_name );
}
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE {$options_condition}" );
// phpcs:enable WordPress.DB.PreparedSQL
$forms = get_posts(
array(
'post_type' => array( 'jet-form-builder' ),
'post_status' => 'any',
'numberposts' => - 1,
'fields' => 'ids',
)
);
if ( $forms ) {
foreach ( $forms as $form_id ) {
wp_delete_post( $form_id, true );
}
}
/**
* @var WP_Filesystem_Base $wp_filesystem
*/
global $wp_filesystem;
$uploads_directory = wp_upload_dir();
if ( empty( $uploads_directory['error'] ) ) {
$wp_filesystem->rmdir( $uploads_directory['basedir'] . '/jet-form-builder/', true );
}
( new JFB_Modules\Jobs\Module() )->unschedule_all();