wpforms-lite
Last commit date
assets
5 years ago
includes
5 years ago
libs
5 years ago
lite
5 years ago
src
5 years ago
templates
5 years ago
vendor
5 years ago
changelog.txt
5 years ago
readme.txt
5 years ago
uninstall.php
5 years ago
wpforms.php
5 years ago
uninstall.php
129 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 | // phpcs:disable WordPress.DB.DirectDatabaseQuery |
| 23 | |
| 24 | // Exit if accessed directly. |
| 25 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 26 | exit; |
| 27 | } |
| 28 | |
| 29 | // Load plugin file. |
| 30 | require_once 'wpforms.php'; |
| 31 | |
| 32 | // Disable Action Schedule Queue Runner. |
| 33 | if ( class_exists( 'ActionScheduler_QueueRunner' ) ) { |
| 34 | ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); |
| 35 | } |
| 36 | |
| 37 | // Confirm user has decided to remove all data, otherwise stop. |
| 38 | $settings = get_option( 'wpforms_settings', [] ); |
| 39 | if ( empty( $settings['uninstall-data'] ) ) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | global $wpdb; |
| 44 | |
| 45 | // Delete entries table. |
| 46 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entries' ); |
| 47 | |
| 48 | // Delete entry meta table. |
| 49 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entry_meta' ); |
| 50 | |
| 51 | // Delete entry fields table. |
| 52 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entry_fields' ); |
| 53 | |
| 54 | // Delete tasks meta table. |
| 55 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 56 | $wpdb->query( 'DROP TABLE IF EXISTS ' . \WPForms\Tasks\Meta::get_table_name() ); |
| 57 | |
| 58 | // Delete logger table. |
| 59 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 60 | $wpdb->query( 'DROP TABLE IF EXISTS ' . \WPForms\Logger\Repository::get_table_name() ); |
| 61 | |
| 62 | // Delete Preview page. |
| 63 | $preview_page = get_option( 'wpforms_preview_page', false ); |
| 64 | if ( ! empty( $preview_page ) ) { |
| 65 | wp_delete_post( $preview_page, true ); |
| 66 | } |
| 67 | |
| 68 | // Delete wpforms and wpforms_log post type posts/post_meta. |
| 69 | $wpforms_posts = get_posts( |
| 70 | [ |
| 71 | 'post_type' => [ 'wpforms_log', 'wpforms' ], |
| 72 | 'post_status' => 'any', |
| 73 | 'numberposts' => - 1, |
| 74 | 'fields' => 'ids', |
| 75 | ] |
| 76 | ); |
| 77 | if ( $wpforms_posts ) { |
| 78 | foreach ( $wpforms_posts as $wpforms_post ) { |
| 79 | wp_delete_post( $wpforms_post, true ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // Delete all the plugin settings. |
| 84 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpforms\_%'" ); |
| 85 | |
| 86 | // Delete widget settings. |
| 87 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'widget\_wpforms%'" ); |
| 88 | |
| 89 | // Delete options from the previous version of the Notifications functionality. |
| 90 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_amn\_wpforms\_%'" ); |
| 91 | |
| 92 | // Delete plugin user meta. |
| 93 | $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'wpforms\_%'" ); |
| 94 | |
| 95 | // Delete plugin term meta. |
| 96 | $wpdb->query( "DELETE FROM {$wpdb->termmeta} WHERE meta_key LIKE 'wpforms\_%'" ); |
| 97 | |
| 98 | // Remove any transients we've left behind. |
| 99 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_wpforms\_%'" ); |
| 100 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_site\_transient\_wpforms\_%'" ); |
| 101 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\_wpforms\_%'" ); |
| 102 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_site\_transient\_timeout\_wpforms\_%'" ); |
| 103 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_wpforms\_transient\_%'" ); |
| 104 | |
| 105 | global $wp_filesystem; |
| 106 | |
| 107 | // Remove uploaded files. |
| 108 | $uploads_directory = wp_upload_dir(); |
| 109 | if ( empty( $uploads_directory['error'] ) ) { |
| 110 | $wp_filesystem->rmdir( $uploads_directory['basedir'] . '/wpforms/', true ); |
| 111 | } |
| 112 | |
| 113 | // Remove translation files. |
| 114 | $languages_directory = defined( 'WP_LANG_DIR' ) ? trailingslashit( WP_LANG_DIR ) : trailingslashit( WP_CONTENT_DIR ) . 'languages/'; |
| 115 | $translations = glob( wp_normalize_path( $languages_directory . 'plugins/wpforms-*' ) ); |
| 116 | if ( ! empty( $translations ) ) { |
| 117 | foreach ( $translations as $file ) { |
| 118 | $wp_filesystem->delete( $file ); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Remove plugin cron jobs. |
| 123 | wp_clear_scheduled_hook( 'wpforms_email_summaries_cron' ); |
| 124 | |
| 125 | // Unschedule all plugin ActionScheduler actions. |
| 126 | // Don't use wpforms() because 'tasks' in core are registered on `init` hook, |
| 127 | // which is not executed on uninstall. |
| 128 | ( new \WPForms\Tasks\Tasks() )->cancel_all(); |
| 129 |