wpforms-lite
Last commit date
assets
1 year ago
includes
1 year ago
lite
1 year ago
src
1 year ago
templates
1 year ago
vendor
1 year ago
vendor_prefixed
1 year ago
changelog.txt
1 year ago
readme.txt
1 year ago
uninstall.php
1 year ago
wpforms.php
1 year ago
uninstall.php
170 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Uninstall WPForms. |
| 4 | * |
| 5 | * Remove: |
| 6 | * - Entries table |
| 7 | * - Entry Meta table |
| 8 | * - Entry fields table |
| 9 | * - Form Preview page |
| 10 | * - wpforms_log post type posts and post_meta |
| 11 | * - wpforms post type posts and post_meta |
| 12 | * - WPForms settings/options |
| 13 | * - WPForms user meta |
| 14 | * - WPForms term meta |
| 15 | * - WPForms Uploads |
| 16 | * |
| 17 | * @since 1.4.5 |
| 18 | * |
| 19 | * @var WP_Filesystem_Base $wp_filesystem |
| 20 | */ |
| 21 | |
| 22 | // Exit if accessed directly. |
| 23 | use WPForms\Db\Payments\Meta as PaymentsMeta; |
| 24 | use WPForms\Db\Payments\Payment; |
| 25 | use WPForms\Logger\Repository; |
| 26 | use WPForms\Tasks\Meta as TasksMeta; |
| 27 | use WPForms\Tasks\Tasks; |
| 28 | |
| 29 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 30 | exit; |
| 31 | } |
| 32 | |
| 33 | // Load plugin file. |
| 34 | require_once 'wpforms.php'; |
| 35 | |
| 36 | // Disable Action Schedule Queue Runner. |
| 37 | if ( class_exists( 'ActionScheduler_QueueRunner' ) ) { |
| 38 | ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); |
| 39 | } |
| 40 | |
| 41 | // Confirm user has decided to remove all data, otherwise stop. |
| 42 | $settings = get_option( 'wpforms_settings', [] ); |
| 43 | |
| 44 | if ( |
| 45 | empty( $settings['uninstall-data'] ) || |
| 46 | is_plugin_active( 'wpforms/wpforms.php' ) || |
| 47 | is_plugin_active( 'wpforms-lite/wpforms.php' ) |
| 48 | ) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | global $wpdb; |
| 53 | |
| 54 | // phpcs:disable WordPress.DB.DirectDatabaseQuery |
| 55 | |
| 56 | // Delete entries table. |
| 57 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entries' ); |
| 58 | |
| 59 | // Delete entry meta table. |
| 60 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entry_meta' ); |
| 61 | |
| 62 | // Delete entry fields table. |
| 63 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entry_fields' ); |
| 64 | |
| 65 | // Delete payments table. |
| 66 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 67 | $wpdb->query( 'DROP TABLE IF EXISTS ' . Payment::get_table_name() ); |
| 68 | |
| 69 | // Delete payment meta table. |
| 70 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 71 | $wpdb->query( 'DROP TABLE IF EXISTS ' . PaymentsMeta::get_table_name() ); |
| 72 | |
| 73 | // Delete tasks meta table. |
| 74 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 75 | $wpdb->query( 'DROP TABLE IF EXISTS ' . TasksMeta::get_table_name() ); |
| 76 | |
| 77 | // Delete logger table. |
| 78 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 79 | $wpdb->query( 'DROP TABLE IF EXISTS ' . Repository::get_table_name() ); |
| 80 | |
| 81 | /** |
| 82 | * Delete tables that might be created by "Add-ons". |
| 83 | * |
| 84 | * 1. Form Locker. |
| 85 | * 2. User Journey. |
| 86 | * 3. Coupons. |
| 87 | */ |
| 88 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_form_locker_email_verification' ); |
| 89 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_user_journey' ); |
| 90 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_coupons' ); |
| 91 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_coupons_forms' ); |
| 92 | |
| 93 | // Delete Preview page. |
| 94 | $preview_page = get_option( 'wpforms_preview_page', false ); |
| 95 | |
| 96 | if ( ! empty( $preview_page ) ) { |
| 97 | wp_delete_post( $preview_page, true ); |
| 98 | } |
| 99 | |
| 100 | // Delete wpforms, wpforms-template and wpforms_log post type posts/post_meta. |
| 101 | $wpforms_posts = get_posts( |
| 102 | [ |
| 103 | 'post_type' => [ 'wpforms_log', 'wpforms', 'wpforms-template' ], |
| 104 | 'post_status' => [ 'any', 'trash', 'auto-draft' ], |
| 105 | 'numberposts' => -1, |
| 106 | 'fields' => 'ids', |
| 107 | ] |
| 108 | ); |
| 109 | |
| 110 | if ( $wpforms_posts ) { |
| 111 | foreach ( $wpforms_posts as $wpforms_post ) { |
| 112 | wp_delete_post( $wpforms_post, true ); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Delete all the plugin settings. |
| 117 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'wpforms\_%'" ); |
| 118 | |
| 119 | // Delete widget settings. |
| 120 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'widget\_wpforms%'" ); |
| 121 | |
| 122 | // Delete options from the previous version of the Notifications functionality. |
| 123 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_amn\_wpforms\_%'" ); |
| 124 | |
| 125 | // Delete plugin user meta. |
| 126 | $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'wpforms\_%'" ); |
| 127 | |
| 128 | // Delete plugin term meta. |
| 129 | $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key LIKE 'wpforms\_%'" ); |
| 130 | |
| 131 | // Remove any transients we've left behind. |
| 132 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_wpforms\_%'" ); |
| 133 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_site\_transient\_wpforms\_%'" ); |
| 134 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_timeout\_wpforms\_%'" ); |
| 135 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_site\_transient\_timeout\_wpforms\_%'" ); |
| 136 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_wpforms\_transient\_%'" ); |
| 137 | |
| 138 | global $wp_filesystem; |
| 139 | |
| 140 | // Remove uploaded files. |
| 141 | $uploads_directory = wp_upload_dir(); |
| 142 | |
| 143 | if ( empty( $uploads_directory['error'] ) ) { |
| 144 | $wp_filesystem->rmdir( $uploads_directory['basedir'] . '/wpforms/', true ); |
| 145 | } |
| 146 | |
| 147 | // Remove translation files. |
| 148 | $languages_directory = defined( 'WP_LANG_DIR' ) ? trailingslashit( WP_LANG_DIR ) : trailingslashit( WP_CONTENT_DIR ) . 'languages/'; |
| 149 | $translations = glob( wp_normalize_path( $languages_directory . 'plugins/wpforms-*' ) ); |
| 150 | |
| 151 | if ( ! empty( $translations ) ) { |
| 152 | foreach ( $translations as $file ) { |
| 153 | $wp_filesystem->delete( $file ); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // Remove plugin cron jobs. |
| 158 | wp_clear_scheduled_hook( 'wpforms_email_summaries_cron' ); |
| 159 | |
| 160 | // Check if the event is scheduled before attempting to clear it. |
| 161 | // This event is only registered for the Lite edition of the plugin. |
| 162 | if ( wp_next_scheduled( 'wpforms_weekly_entries_count_cron' ) ) { |
| 163 | wp_clear_scheduled_hook( 'wpforms_weekly_entries_count_cron' ); |
| 164 | } |
| 165 | |
| 166 | // Un-schedule all plugin ActionScheduler actions. |
| 167 | // Don't use wpforms() because 'tasks' in core are registered on `init` hook, |
| 168 | // which is not executed on uninstallation. |
| 169 | ( new Tasks() )->cancel_all(); |
| 170 |