wpforms-lite
Last commit date
assets
6 years ago
includes
6 years ago
languages
6 years ago
lite
6 years ago
src
6 years ago
templates
6 years ago
vendor
6 years ago
changelog.txt
6 years ago
readme.txt
6 years ago
uninstall.php
6 years ago
wpforms.php
6 years ago
uninstall.php
111 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 | // Confirm user has decided to remove all data, otherwise stop. |
| 33 | $settings = get_option( 'wpforms_settings', array() ); |
| 34 | if ( empty( $settings['uninstall-data'] ) ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | global $wpdb; |
| 39 | |
| 40 | // Delete entries table. |
| 41 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entries' ); |
| 42 | |
| 43 | // Delete entry meta table. |
| 44 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entry_meta' ); |
| 45 | |
| 46 | // Delete entry fields table. |
| 47 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'wpforms_entry_fields' ); |
| 48 | |
| 49 | // Delete tasks meta table. |
| 50 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 51 | $wpdb->query( 'DROP TABLE IF EXISTS ' . \WPForms\Tasks\Meta::get_table_name() ); |
| 52 | |
| 53 | // Delete Preview page. |
| 54 | $preview_page = get_option( 'wpforms_preview_page', false ); |
| 55 | if ( ! empty( $preview_page ) ) { |
| 56 | wp_delete_post( $preview_page, true ); |
| 57 | } |
| 58 | |
| 59 | // Delete wpforms and wpforms_log post type posts/post_meta. |
| 60 | $wpforms_posts = get_posts( |
| 61 | array( |
| 62 | 'post_type' => array( 'wpforms_log', 'wpforms' ), |
| 63 | 'post_status' => 'any', |
| 64 | 'numberposts' => - 1, |
| 65 | 'fields' => 'ids', |
| 66 | ) |
| 67 | ); |
| 68 | if ( $wpforms_posts ) { |
| 69 | foreach ( $wpforms_posts as $wpforms_post ) { |
| 70 | wp_delete_post( $wpforms_post, true ); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // Delete plugin settings. |
| 75 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpforms\_%'" ); |
| 76 | |
| 77 | // Delete plugin user meta. |
| 78 | $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'wpforms\_%'" ); |
| 79 | |
| 80 | // Delete plugin term meta. |
| 81 | $wpdb->query( "DELETE FROM {$wpdb->termmeta} WHERE meta_key LIKE 'wpforms\_%'" ); |
| 82 | |
| 83 | // Remove any transients we've left behind. |
| 84 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_wpforms\_%'" ); |
| 85 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_site\_transient\_wpforms\_%'" ); |
| 86 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\_wpforms\_%'" ); |
| 87 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_site\_transient\_timeout\_wpforms\_%'" ); |
| 88 | |
| 89 | global $wp_filesystem; |
| 90 | |
| 91 | // Remove uploaded files. |
| 92 | $uploads_directory = wp_upload_dir(); |
| 93 | if ( empty( $uploads_directory['error'] ) ) { |
| 94 | $wp_filesystem->rmdir( $uploads_directory['basedir'] . '/wpforms/', true ); |
| 95 | } |
| 96 | |
| 97 | // Remove translation files. |
| 98 | $languages_directory = defined( 'WP_LANG_DIR' ) ? trailingslashit( WP_LANG_DIR ) : trailingslashit( WP_CONTENT_DIR ) . 'languages/'; |
| 99 | $translations = glob( wp_normalize_path( $languages_directory . 'plugins/wpforms-*' ) ); |
| 100 | if ( ! empty( $translations ) ) { |
| 101 | foreach ( $translations as $file ) { |
| 102 | $wp_filesystem->delete( $file ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Remove plugin cron jobs. |
| 107 | wp_clear_scheduled_hook( 'wpforms_email_summaries_cron' ); |
| 108 | |
| 109 | // Unschedule all ActionScheduler actions by group. |
| 110 | wpforms()->get( 'tasks' )->cancel_all(); |
| 111 |