| 1 |
<?php |
| 2 |
/** |
| 3 |
* @since 3.0.0 |
| 4 |
*/ |
| 5 |
|
| 6 |
// phpcs:disable WordPress.DB.DirectDatabaseQuery |
| 7 |
|
| 8 |
// if uninstall.php is not called by WordPress, die |
| 9 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 10 |
die; |
| 11 |
} |
| 12 |
|
| 13 |
require_once 'jet-form-builder.php'; |
| 14 |
|
| 15 |
// Disable Action Schedule Queue Runner. |
| 16 |
if ( class_exists( 'ActionScheduler_QueueRunner' ) ) { |
| 17 |
ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); |
| 18 |
} |
| 19 |
|
| 20 |
$options = get_option( 'jet_form_builder_settings__options-tab' ); |
| 21 |
|
| 22 |
if ( ! $options ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
$options = json_decode( $options, true ); |
| 27 |
|
| 28 |
if ( empty( $options['clear_on_uninstall'] ) ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
$opt_prefixes = array( |
| 33 |
'jet\_form\_builder\_settings\_\_', |
| 34 |
'jet\_fb\_', |
| 35 |
'jfb\-', |
| 36 |
'jfb\_', |
| 37 |
); |
| 38 |
$additional_prefixes = array(); |
| 39 |
|
| 40 |
foreach ( $opt_prefixes as $prefix ) { |
| 41 |
array_push( |
| 42 |
$additional_prefixes, |
| 43 |
'\_transient\_' . $prefix, |
| 44 |
'\_site\_transient\_' . $prefix, |
| 45 |
'\_transient\_timeout\_' . $prefix, |
| 46 |
'\_site\_transient\_timeout\_' . $prefix |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
$opt_prefixes = array_merge( $opt_prefixes, $additional_prefixes ); |
| 51 |
|
| 52 |
$options_condition = "option_name LIKE '" . implode( "%' OR option_name LIKE '", $opt_prefixes ) . "%'"; |
| 53 |
|
| 54 |
$tables = array( |
| 55 |
// secondary tables |
| 56 |
'tokens_to_records', |
| 57 |
'records_actions', |
| 58 |
'records_errors', |
| 59 |
'records_fields', |
| 60 |
'subscription_to_payer_shipping', |
| 61 |
'subscriptions_to_records', |
| 62 |
'subscriptions_to_payments', |
| 63 |
'subscriptions_notes', |
| 64 |
'payment_to_payer_shipping', |
| 65 |
'payments_to_records', |
| 66 |
'payers_shipping', |
| 67 |
// primary tables |
| 68 |
'tokens', |
| 69 |
'csrf_tokens', |
| 70 |
'recurring_cycles', |
| 71 |
'subscriptions', |
| 72 |
'payments', |
| 73 |
'migrations', |
| 74 |
'payers', |
| 75 |
'records', |
| 76 |
); |
| 77 |
|
| 78 |
global $wpdb; |
| 79 |
|
| 80 |
// phpcs:disable WordPress.DB.PreparedSQL |
| 81 |
|
| 82 |
foreach ( $tables as $table_name ) { |
| 83 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'jet_fb_' . $table_name ); |
| 84 |
} |
| 85 |
|
| 86 |
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE {$options_condition}" ); |
| 87 |
|
| 88 |
// phpcs:enable WordPress.DB.PreparedSQL |
| 89 |
|
| 90 |
$forms = get_posts( |
| 91 |
array( |
| 92 |
'post_type' => array( 'jet-form-builder' ), |
| 93 |
'post_status' => 'any', |
| 94 |
'numberposts' => - 1, |
| 95 |
'fields' => 'ids', |
| 96 |
) |
| 97 |
); |
| 98 |
if ( $forms ) { |
| 99 |
foreach ( $forms as $form_id ) { |
| 100 |
wp_delete_post( $form_id, true ); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* @var WP_Filesystem_Base $wp_filesystem |
| 106 |
*/ |
| 107 |
global $wp_filesystem; |
| 108 |
|
| 109 |
$uploads_directory = wp_upload_dir(); |
| 110 |
if ( empty( $uploads_directory['error'] ) ) { |
| 111 |
$wp_filesystem->rmdir( $uploads_directory['basedir'] . '/jet-form-builder/', true ); |
| 112 |
} |
| 113 |
|
| 114 |
( new JFB_Modules\Jobs\Module() )->unschedule_all(); |
| 115 |
|