jetformbuilder
Last commit date
assets
3 years ago
framework
3 years ago
includes
3 years ago
languages
3 years ago
templates
3 years ago
README.md
3 years ago
composer.json
3 years ago
index.php
3 years ago
jet-form-builder.php
3 years ago
readme.txt
3 years ago
uninstall.php
3 years ago
wp-cli.local.yml
3 years ago
uninstall.php
102 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @since 3.0.0 |
| 4 | */ |
| 5 | // phpcs:disable WordPress.DB.DirectDatabaseQuery |
| 6 | |
| 7 | // if uninstall.php is not called by WordPress, die |
| 8 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 9 | die; |
| 10 | } |
| 11 | |
| 12 | $options = get_option( 'jet_form_builder_settings__options-tab' ); |
| 13 | |
| 14 | if ( ! $options ) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | $options = json_decode( $options, true ); |
| 19 | |
| 20 | if ( empty( $options['clear_on_uninstall'] ) ) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | $opt_prefixes = array( |
| 25 | 'jet\_form\_builder\_settings\_\_', |
| 26 | 'jet\_fb\_', |
| 27 | 'jfb\-', |
| 28 | 'jfb\_' |
| 29 | ); |
| 30 | $additional_prefixes = array(); |
| 31 | |
| 32 | foreach ( $opt_prefixes as $prefix ) { |
| 33 | array_push( |
| 34 | $additional_prefixes, |
| 35 | '\_transient\_' . $prefix, |
| 36 | '\_site\_transient\_' . $prefix, |
| 37 | '\_transient\_timeout\_' . $prefix, |
| 38 | '\_site\_transient\_timeout\_' . $prefix |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | $opt_prefixes = array_merge( $opt_prefixes, $additional_prefixes ); |
| 43 | |
| 44 | $options_condition = "option_name LIKE '" . implode( "%' OR option_name LIKE '", $opt_prefixes ) . "%'"; |
| 45 | |
| 46 | $tables = array( |
| 47 | // secondary tables |
| 48 | 'records_actions', |
| 49 | 'records_errors', |
| 50 | 'records_fields', |
| 51 | 'subscription_to_payer_shipping', |
| 52 | 'subscriptions_to_records', |
| 53 | 'subscriptions_to_payments', |
| 54 | 'subscriptions_notes', |
| 55 | 'payment_to_payer_shipping', |
| 56 | 'payments_to_records', |
| 57 | 'payers_shipping', |
| 58 | // primary tables |
| 59 | 'csrf_tokens', |
| 60 | 'recurring_cycles', |
| 61 | 'subscriptions', |
| 62 | 'payments', |
| 63 | 'migrations', |
| 64 | 'payers', |
| 65 | 'records', |
| 66 | ); |
| 67 | |
| 68 | /** |
| 69 | * @var wpdb $wpdb |
| 70 | */ |
| 71 | global $wpdb; |
| 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 | $forms = get_posts( |
| 80 | [ |
| 81 | 'post_type' => [ 'jet-form-builder' ], |
| 82 | 'post_status' => 'any', |
| 83 | 'numberposts' => - 1, |
| 84 | 'fields' => 'ids', |
| 85 | ] |
| 86 | ); |
| 87 | if ( $forms ) { |
| 88 | foreach ( $forms as $form_id ) { |
| 89 | wp_delete_post( $form_id, true ); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @var WP_Filesystem_Base $wp_filesystem |
| 95 | */ |
| 96 | global $wp_filesystem; |
| 97 | |
| 98 | $uploads_directory = wp_upload_dir(); |
| 99 | if ( empty( $uploads_directory['error'] ) ) { |
| 100 | $wp_filesystem->rmdir( $uploads_directory['basedir'] . '/jet-form-builder/', true ); |
| 101 | } |
| 102 |