PluginProbe
Selection Lite / trunk
Selection Lite vtrunk
trunk 1.0 1.1 1.10 1.11 1.12 1.14 1.15 1.16 1.17 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
selection-lite / uninstall.php

uninstall.php in Selection Lite trunk, at uninstall.php

210 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Selection Lite
4 * Carefully selected Elementor addons bundle, for building the most awesome websites
5 *
6 * @encoding UTF-8
7 * @version 1.17
8 * @copyright (C) 2018-2026 Merkulove ( https://merkulov.design/ ). All rights reserved.
9 * @license GPLv3
10 * @contributors merkulove, vladcherviakov, phoenixmkua, podolianochka, viktorialev01
11 * @support help@merkulov.design
12 **/
13
14 namespace Merkulove;
15
16 /** Exit if accessed directly. */
17 if ( ! defined( 'ABSPATH' ) ) {
18 header( 'Status: 403 Forbidden' );
19 header( 'HTTP/1.1 403 Forbidden' );
20 exit;
21 }
22
23 /** Exit if uninstall.php is not called by WordPress. */
24 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
25 exit;
26 }
27
28 /** Include plugin autoloader for additional classes. */
29 require __DIR__ . '/src/autoload.php';
30
31 use Merkulove\SelectionLite\Unity\Plugin;
32
33 /**
34 * SINGLETON: Class used to implement plugin uninstallation.
35 *
36 * @since 1.0
37 *
38 **/
39 final class Uninstall {
40
41 /**
42 * The one true Uninstallation.
43 *
44 * @since 1.0
45 * @var Uninstall
46 **/
47 private static $instance;
48
49 /**
50 * Sets up a new Uninstallation instance.
51 *
52 * @since 1.0
53 * @access public
54 **/
55 private function __construct() {
56
57 /** Get Uninstall mode. */
58 $uninstall_mode = $this->get_uninstall_mode();
59
60 /** Remove Plugin and Settings. */
61 if ( 'plugin+settings' === $uninstall_mode ) {
62
63 /** Remove Plugin Settings. */
64 $this->remove_settings();
65
66 }
67
68 }
69
70 /**
71 * Delete Plugin Options.
72 *
73 * @since 1.0
74 * @access private
75 *
76 * @return void
77 **/
78 private function remove_settings() {
79
80 /** Prepare array with options to remove. */
81 $settings = [];
82
83 foreach ( wp_load_alloptions() as $option => $value ) {
84 if ( strpos( $option, 'mdp_selection_lite' ) === 0 ) {
85 $settings[] = $option;
86 }
87 }
88
89 /** Remove options for Multisite. */
90 if ( is_multisite() ) {
91
92 foreach ( $settings as $key ) {
93
94 if ( ! get_site_option( $key ) ) { continue; }
95
96 delete_site_option( $key );
97
98 }
99
100 /** Remove options for Singular site. */
101 } else {
102
103 foreach ( $settings as $key ) {
104
105 if ( ! get_option( $key ) ) { continue; }
106
107 delete_option( $key );
108
109 }
110
111 }
112
113 }
114
115 /**
116 * Delete Plugin data.
117 * Remove all tables started with plugin slug and folder from Uploads.
118 *
119 * @since 1.0
120 * @access private
121 *
122 * @return void
123 **/
124 private function remove_data() {
125
126 /** Remove all tables started with plugin slug. */
127 $this->remove_tables();
128
129 }
130
131 /**
132 * Remove all tables started with plugin slug.
133 *
134 * @since 1.0
135 * @access private
136 *
137 * @return void
138 **/
139 private function remove_tables() {
140
141 global $wpdb;
142
143 $tables = $wpdb->tables();
144 foreach ( $tables as $table_name ) {
145
146 /** Convert plugin slug to table name. */
147 $table_slug = str_replace( '-', '_', Plugin::get_slug() );
148
149 /** If table name starts with prefix_plugin_slug */
150 if ( strpos( $table_name, $wpdb->prefix . $table_slug ) === 0 ) {
151 if ($wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) ) == $table_name) {
152 $wpdb->query( $wpdb->prepare( "TRUNCATE TABLE %s", $table_name ) );
153 }
154 }
155
156 }
157
158 }
159
160 /**
161 * Return uninstall mode.
162 * plugin - Will remove the plugin only. Settings and Audio files will be saved. Used when updating the plugin.
163 * plugin+settings - Will remove the plugin and settings. Audio files will be saved. As a result, all settings will be set to default values. Like after the first installation.
164 *
165 * @since 1.0
166 * @access public
167 *
168 * @return string
169 **/
170 public function get_uninstall_mode() {
171
172 $uninstall_settings = get_option( 'mdp_selection_lite_uninstall_settings' );
173
174 if ( isset( $uninstall_settings[ 'mdp_selection_lite_uninstall_settings' ] ) && $uninstall_settings[ 'mdp_selection_lite_uninstall_settings' ] ) { // Default value.
175 $uninstall_settings = [
176 'delete_plugin' => 'plugin'
177 ];
178 }
179
180 return $uninstall_settings[ 'delete_plugin' ];
181
182 }
183
184 /**
185 * Main Uninstallation Instance.
186 *
187 * Insures that only one instance of Uninstall exists in memory at any one time.
188 *
189 * @static
190 * @since 1.0
191 *
192 * @return Uninstall
193 **/
194 public static function get_instance() {
195
196 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
197
198 self::$instance = new self;
199
200 }
201
202 return self::$instance;
203
204 }
205
206 }
207
208 /** Call Unity Uninstall. */
209 Uninstall::get_instance();
210