PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.0
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Util / Uninstallation.php

Uninstallation.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.1.0, at includes/Core/Util/Uninstallation.php

128 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Util;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8 use WP_Site;
9
10 /**
11 * Class handling plugin uninstallation.
12 *
13 * @since 1.0.0
14 * @access private
15 * @ignore
16 */
17 final class Uninstallation
18 {
19 /**
20 * Registers functionality through WordPress hooks.
21 *
22 * @since 1.0.0
23 */
24 public function register()
25 {
26 add_action('bitforms_uninstall', [self::class, 'uninstall']);
27 add_action('wp_uninitialize_site', [$this, 'uninitializeSite']);
28 }
29
30 /**
31 * Will run on deletion of plugin from plugin page.
32 * N.B: this method must have to be static otherwise will not run in deletion
33 *
34 */
35 public static function uninstall()
36 {
37 flush_rewrite_rules();
38 if (is_multisite()) {
39 $sites = get_sites(['fields' => 'ids', 'network_id' => get_current_network_id()]);
40 foreach ($sites as $site) {
41 switch_to_blog($site);
42 self::deleteFromCurrentSite();
43 restore_current_blog();
44 }
45 } else {
46 self::deleteFromCurrentSite();
47 }
48 }
49
50 public static function deleteFromCurrentSite()
51 {
52 $routes = get_option('bitforms_routes');
53 if ($routes && isset($routes['root'])) {
54 wp_delete_post($routes['root']);
55 wp_delete_post($routes['file']);
56 }
57
58 $data = get_option('bitform_app_config');
59 if ($data && isset($data->delete_table) && $data->delete_table) {
60 self::dropTables();
61 }
62 self::deleteOptions();
63 }
64
65 public function uninitializeSite(WP_Site $oldSite)
66 {
67 switch_to_blog($oldSite->blog_id);
68 self::dropTables();
69 restore_current_blog();
70 }
71
72 public static function dropTables()
73 {
74 global $wpdb;
75 $tableArray = [
76 'bitforms_email_template',
77 'bitforms_form',
78 'bitforms_form_entries',
79 'bitforms_form_entrymeta',
80 'bitforms_form_entry_log',
81 'bitforms_form_log_details',
82 'bitforms_integration',
83 'bitforms_reports',
84 'bitforms_success_messages',
85 'bitforms_workflows',
86 'bitforms_form_entry_relatedinfo',
87 'bitforms_form_v1',
88 'bitforms_success_messages_v1',
89 'bitforms_workflows_v1',
90 ];
91
92 foreach ($tableArray as $tablename) {
93 $wpdb->query($wpdb->prepare('DROP TABLE IF EXISTS `%1s`', $wpdb->prefix . $tablename));
94 }
95 }
96
97 public static function deleteOptions()
98 {
99 global $wpdb;
100 $pluginOptions = [
101 'bitform_app_config',
102 'bitform_app_settings',
103 'bitforms_routes',
104 'bitforms_db_version',
105 'bitforms_installed',
106 'bitforms_version',
107 'bitforms_routes',
108 'bitform_secret_api_key',
109 'bitforms_migrated_to_v2',
110 'bitforms_migrating_to_v2',
111 'bitforms_changelog_version',
112 'bitforms_hide_announcement',
113 'bitforms_hide_cashback',
114 'bitform_csrf_secret',
115 'bitform_form_update_version',
116 'bitforms_salt',
117 ];
118
119 $placeholders = implode(',', array_fill(0, count($pluginOptions), '%s'));
120 $wpdb->query(
121 $wpdb->prepare(
122 'DELETE FROM `' . $wpdb->prefix . 'options` WHERE option_name IN (' . $placeholders . ')',
123 ...$pluginOptions
124 )
125 );
126 }
127 }
128