jetformbuilder
Last commit date
assets
2 years ago
compatibility
2 years ago
components
2 years ago
includes
2 years ago
languages
2 years ago
modules
2 years ago
templates
2 years ago
README.md
2 years ago
index.php
2 years ago
jet-form-builder.php
2 years ago
readme.txt
2 years ago
uninstall.php
2 years ago
uninstall.php
104 lines
| 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 | $options = get_option( 'jet_form_builder_settings__options-tab' ); |
| 14 | |
| 15 | if ( ! $options ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | $options = json_decode( $options, true ); |
| 20 | |
| 21 | if ( empty( $options['clear_on_uninstall'] ) ) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $opt_prefixes = array( |
| 26 | 'jet\_form\_builder\_settings\_\_', |
| 27 | 'jet\_fb\_', |
| 28 | 'jfb\-', |
| 29 | 'jfb\_', |
| 30 | ); |
| 31 | $additional_prefixes = array(); |
| 32 | |
| 33 | foreach ( $opt_prefixes as $prefix ) { |
| 34 | array_push( |
| 35 | $additional_prefixes, |
| 36 | '\_transient\_' . $prefix, |
| 37 | '\_site\_transient\_' . $prefix, |
| 38 | '\_transient\_timeout\_' . $prefix, |
| 39 | '\_site\_transient\_timeout\_' . $prefix |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | $opt_prefixes = array_merge( $opt_prefixes, $additional_prefixes ); |
| 44 | |
| 45 | $options_condition = "option_name LIKE '" . implode( "%' OR option_name LIKE '", $opt_prefixes ) . "%'"; |
| 46 | |
| 47 | $tables = array( |
| 48 | // secondary tables |
| 49 | 'records_actions', |
| 50 | 'records_errors', |
| 51 | 'records_fields', |
| 52 | 'subscription_to_payer_shipping', |
| 53 | 'subscriptions_to_records', |
| 54 | 'subscriptions_to_payments', |
| 55 | 'subscriptions_notes', |
| 56 | 'payment_to_payer_shipping', |
| 57 | 'payments_to_records', |
| 58 | 'payers_shipping', |
| 59 | // primary tables |
| 60 | 'csrf_tokens', |
| 61 | 'recurring_cycles', |
| 62 | 'subscriptions', |
| 63 | 'payments', |
| 64 | 'migrations', |
| 65 | 'payers', |
| 66 | 'records', |
| 67 | ); |
| 68 | |
| 69 | global $wpdb; |
| 70 | |
| 71 | // phpcs:disable WordPress.DB.PreparedSQL |
| 72 | |
| 73 | foreach ( $tables as $table_name ) { |
| 74 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'jet_fb_' . $table_name ); |
| 75 | } |
| 76 | |
| 77 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE {$options_condition}" ); |
| 78 | |
| 79 | // phpcs:enable WordPress.DB.PreparedSQL |
| 80 | |
| 81 | $forms = get_posts( |
| 82 | array( |
| 83 | 'post_type' => array( 'jet-form-builder' ), |
| 84 | 'post_status' => 'any', |
| 85 | 'numberposts' => - 1, |
| 86 | 'fields' => 'ids', |
| 87 | ) |
| 88 | ); |
| 89 | if ( $forms ) { |
| 90 | foreach ( $forms as $form_id ) { |
| 91 | wp_delete_post( $form_id, true ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @var WP_Filesystem_Base $wp_filesystem |
| 97 | */ |
| 98 | global $wp_filesystem; |
| 99 | |
| 100 | $uploads_directory = wp_upload_dir(); |
| 101 | if ( empty( $uploads_directory['error'] ) ) { |
| 102 | $wp_filesystem->rmdir( $uploads_directory['basedir'] . '/jet-form-builder/', true ); |
| 103 | } |
| 104 |