PluginProbe
Selection Lite / 1.8
Selection Lite v1.8
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 1.8, at uninstall.php

208 lines 4.7 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.8
8 * @copyright (C) 2018 - 2023 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 /** Include plugin autoloader for additional classes. */
24 require __DIR__ . '/src/autoload.php';
25
26 use Merkulove\SelectionLite\Unity\Plugin;
27
28 /**
29 * SINGLETON: Class used to implement plugin uninstallation.
30 *
31 * @since 1.0
32 *
33 **/
34 final class Uninstall {
35
36 /**
37 * The one true Uninstallation.
38 *
39 * @since 1.0
40 * @var Uninstall
41 **/
42 private static $instance;
43
44 /**
45 * Sets up a new Uninstallation instance.
46 *
47 * @since 1.0
48 * @access public
49 **/
50 private function __construct() {
51
52 /** Get Uninstall mode. */
53 $uninstall_mode = $this->get_uninstall_mode();
54
55 /** Remove Plugin and Settings. */
56 if ( 'plugin+settings' === $uninstall_mode ) {
57
58 /** Remove Plugin Settings. */
59 $this->remove_settings();
60
61 }
62
63 }
64
65 /**
66 * Delete Plugin Options.
67 *
68 * @since 1.0
69 * @access private
70 *
71 * @return void
72 **/
73 private function remove_settings() {
74
75 /** Prepare array with options to remove. */
76 $settings = [];
77
78 foreach ( wp_load_alloptions() as $option => $value ) {
79 if ( strpos( $option, 'mdp_selection_lite' ) === 0 ) {
80 $settings[] = $option;
81 }
82 }
83
84 /** Remove options for Multisite. */
85 if ( is_multisite() ) {
86
87 foreach ( $settings as $key ) {
88
89 if ( ! get_site_option( $key ) ) { continue; }
90
91 delete_site_option( $key );
92
93 }
94
95 /** Remove options for Singular site. */
96 } else {
97
98 foreach ( $settings as $key ) {
99
100 if ( ! get_option( $key ) ) { continue; }
101
102 delete_option( $key );
103
104 }
105
106 }
107
108 }
109
110 /**
111 * Delete Plugin data.
112 * Remove all tables started with plugin slug and folder from Uploads.
113 *
114 * @since 1.0
115 * @access private
116 *
117 * @return void
118 **/
119 private function remove_data() {
120
121 /** Remove all tables started with plugin slug. */
122 $this->remove_tables();
123
124 }
125
126 /**
127 * Remove all tables started with plugin slug.
128 *
129 * @since 1.0
130 * @access private
131 *
132 * @return void
133 **/
134 private function remove_tables() {
135
136 global $wpdb;
137
138 $tables = $wpdb->tables( 'all' );
139
140 foreach ( $tables as $table ) {
141
142 /** Convert plugin slug to table name. */
143 $table_slug = str_replace( '-', '_', Plugin::get_slug() );
144
145 /** If table name starts with prefix_plugin_slug */
146 if ( strpos( $table, $wpdb->prefix . $table_slug ) === 0 ) {
147
148 /** Remove this table. */
149 /** @noinspection SqlNoDataSourceInspection */
150 $wpdb->query( "DROP TABLE IF EXISTS {$table}" );
151
152 }
153
154 }
155
156 }
157
158 /**
159 * Return uninstall mode.
160 * plugin - Will remove the plugin only. Settings and Audio files will be saved. Used when updating the plugin.
161 * 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.
162 *
163 * @since 1.0
164 * @access public
165 *
166 * @return string
167 **/
168 public function get_uninstall_mode() {
169
170 $uninstall_settings = get_option( 'mdp_selection_lite_uninstall_settings' );
171
172 if ( isset( $uninstall_settings[ 'mdp_selection_lite_uninstall_settings' ] ) && $uninstall_settings[ 'mdp_selection_lite_uninstall_settings' ] ) { // Default value.
173 $uninstall_settings = [
174 'delete_plugin' => 'plugin'
175 ];
176 }
177
178 return $uninstall_settings[ 'delete_plugin' ];
179
180 }
181
182 /**
183 * Main Uninstallation Instance.
184 *
185 * Insures that only one instance of Uninstall exists in memory at any one time.
186 *
187 * @static
188 * @since 1.0
189 *
190 * @return Uninstall
191 **/
192 public static function get_instance() {
193
194 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
195
196 self::$instance = new self;
197
198 }
199
200 return self::$instance;
201
202 }
203
204 }
205
206 /** Call Unity Uninstall. */
207 Uninstall::get_instance();
208