PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.3.6
Strong Testimonials v3.3.6
3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / admin / uninstall / class-strong-testimonials-uninstall.php
strong-testimonials / admin / uninstall Last commit date
class-strong-testimonials-uninstall.php 1 year ago
class-strong-testimonials-uninstall.php
286 lines
1 <?php
2
3
4 class Strong_Testimonials_Uninstall {
5
6 /**
7 * @since 2.40.2
8 * Strong_Testimonials_Uninstall constructor.
9 *
10 */
11 public function __construct() {
12
13 // Deactivation
14 add_filter(
15 'plugin_action_links_' . WPMTST_PLUGIN,
16 array(
17 $this,
18 'filter_action_links',
19 )
20 );
21 if ( ! is_network_admin() ) {
22 add_action( 'admin_footer-plugins.php', array( $this, 'add_uninstall_form' ), 16 );
23 }
24 add_action( 'wp_ajax_st_uninstall_plugin', array( $this, 'st_uninstall_plugin' ) );
25 add_action( 'admin_enqueue_scripts', array( $this, 'uninstall_scripts' ) );
26 }
27
28 /**
29 * Enqueue uninstall scripts
30 *
31 * @since 2.40.2
32 */
33 public function uninstall_scripts() {
34
35 $current_screen = get_current_screen();
36 if ( 'plugins' === $current_screen->base ) {
37 wp_enqueue_style( 'st-uninstall', WPMTST_URL . 'admin/css/uninstall.css' );
38 wp_enqueue_script( 'st-uninstall', WPMTST_URL . 'admin/js/st-uninstall.js', array( 'jquery' ), WPMTST_VERSION, true );
39 wp_localize_script(
40 'st-uninstall',
41 'wpStUninstall',
42 array(
43 'redirect_url' => admin_url( '/plugins.php' ),
44 'nonce' => wp_create_nonce( 'st_uninstall_plugin' ),
45 )
46 );
47 }
48 }
49
50 /**
51 * @param $links
52 *
53 * @return array
54 *
55 * @since 2.40.2
56 * Set uninstall link
57 */
58 public function filter_action_links( $links ) {
59
60 $links = array_merge(
61 $links,
62 array(
63 '<a onclick="javascript:event.preventDefault();" id="st-uninstall-link" class="uninstall-st st-red-text" href="#">' . esc_html__( 'Uninstall', 'strong-testimonials' ) . '</a>',
64 )
65 );
66
67 return $links;
68 }
69
70 /**
71 * Form text strings
72 * These can be filtered
73 * @since 2.40.2
74 */
75 public function add_uninstall_form() {
76
77 // Get our strings for the form
78 $form = $this->get_form_info();
79
80 ?>
81 <div class="st-uninstall-form-bg">
82 </div>
83 <div class="st-uninstall-form-wrapper">
84 <span class="st-uninstall-form" id="st-uninstall-form">
85 <div class="st-uninstall-form-head">
86 <h3><strong><?php echo esc_html( $form['heading'] ); ?></strong></h3>
87 <i class="close-uninstall-form">X</i>
88 </div>
89 <div class="st-uninstall-form-body"><p><?php echo wp_kses_post( $form['body'] ); ?></p>
90
91 <?php
92 if ( is_array( $form['options'] ) ) {
93 ?>
94 <div class="st-uninstall-options">
95 <?php
96 foreach ( $form['options'] as $key => $option ) {
97
98 $before_input = '';
99 $after_input = '';
100 if ( 'delete_all' === $key ) {
101 $before_input = '<strong class="st-red-text">';
102 $after_input = '</strong>';
103 }
104
105 echo ' <p class="st-uninstall-options-checkbox" ><input type="checkbox" name="st-' . esc_attr( $key ) . ' " id="st-' . esc_attr( $key ) . '" value="' . esc_attr( $key ) . '"> <label for="st-' . esc_attr( $key ) . '">' . wp_kses_post( $before_input ) . esc_attr( $option['label'] ) . wp_kses_post( $after_input ) . '</label></p><p class="description">' . esc_html( $option['description'] ) . '</p>'; // phpcs:ignore $before_input, $after_input OK
106
107 }
108 ?>
109 </div><!-- .st-uninstall-options -->
110 <?php } ?>
111 </div><!-- .st-uninstall-form-body -->
112 <p class="deactivating-spinner"><span
113 class="spinner"></span><?php echo esc_html__( 'Cleaning...', 'strong-testimonials' ); ?></p>
114 <div class="uninstall">
115 <p>
116 <a id="st-uninstall-submit-form" class="button button-primary"
117 href="#"><?php echo esc_html__( 'Uninstall', 'strong-testimonials' ); ?></a>
118 </p>
119 </div>
120 </span>
121 </div>
122 <?php
123 }
124
125 /*
126 * Form text strings
127 * These are non-filterable and used as fallback in case filtered strings aren't set correctly
128 * @since 2.40.2
129 */
130 public function get_form_info() {
131 $form = array();
132 $form['heading'] = esc_html__( 'Sorry to see you go', 'strong-testimonials' );
133 $form['body'] = '<strong class="st-red-text">' . esc_html__( ' Caution!! This action CANNOT be undone', 'strong-testimonials' ) . '</strong>';
134 $form['options'] = apply_filters(
135 'st_uninstall_options',
136 array(
137 'delete_all' => array(
138 'label' => esc_html__( 'Delete all data', 'strong-testimonials' ),
139 'description' => esc_html__( 'Select this to delete all data Strong Testimonials plugin and it\'s add-ons have set in your database.', 'strong-testimonials' ),
140 ),
141 'delete_options' => array(
142 'label' => esc_html__( 'Delete Strong Testimonials options', 'strong-testimonials' ),
143 'description' => esc_html__( 'Delete options set by Strong Testimonials plugin and it\'s add-ons to options table in the database.', 'strong-testimonials' ),
144 ),
145 'delete_transients' => array(
146 'label' => esc_html__( 'Delete Strong Testimonials set transients', 'strong-testimonials' ),
147 'description' => esc_html__( 'Delete transients set by Strong Testimonials plugin and it\'s add-ons to options table in the database.', 'strong-testimonials' ),
148 ),
149 'delete_cpt' => array(
150 'label' => esc_html__( 'Delete testimonials post type', 'strong-testimonials' ),
151 'description' => esc_html__( 'Delete post types made by Strong Testimonials and it\'s add-ons.', 'strong-testimonials' ),
152 ),
153 'delete_terms' => array(
154 'label' => esc_html__( 'Delete categories', 'strong-testimonials' ),
155 'description' => esc_html__( 'Delete Delete categories made by Strong Testimonials and it\'s add-ons.', 'strong-testimonials' ),
156 ),
157 'delete_st_tables' => array(
158 'label' => esc_html__( 'Delete tables', 'strong-testimonials' ),
159 'description' => esc_html__( 'Delete tables made by Strong Testimonials and it\'s add-ons.', 'strong-testimonials' ),
160 ),
161 )
162 );
163
164 return $form;
165 }
166
167 /**
168 * @since 2.40.2
169 * Strong Testimonials Uninstall procedure
170 */
171 public function st_uninstall_plugin() {
172
173 global $wpdb;
174 check_ajax_referer( 'st_uninstall_plugin', 'security' );
175
176 $uninstall_option = isset( $_POST['options'] ) ? array_map( 'absint', $_POST['options'] ) : false;
177
178 // Delete options
179 if ( 1 === absint( $uninstall_option['delete_options'] ) ) {
180 // filter for options to be added by Strong Testimonial's add-ons
181 $options_array = apply_filters( 'st_uninstall_db_options', array( 'wpmtst_options', 'wpmtst_admin_notices', 'wpmtst_auto_dismiss_notices', 'wpmtst_plugin_version', 'wpmtst_compat_options', 'wpmtst_do_activation_redirect', 'wpmtst_config_errors', 'wpmtst_history', 'wpmtst_addons', 'wpmtst_update_log', 'wpmtst_db_version', 'wpmtst_custom_forms', 'wpmtst_fields', 'wpmtst_form_options', 'strong_testimonials_license_key', 'wpmtst_sticky_views', 'wpmtst_view_options', 'wpmtst_importer_options', 'wpmtst_view_default', 'wpmtst_base_forms', 'widget_strong-testimonials-view-widget', 'strong_testimonials_wisdom_notification_times', 'strong_testimonials_wisdom_block_notice', 'strong_testimonials_license_status', 'strong_testimonials_advanced_settings', 'strong_testimonials_wisdom_last_track_time', 'strong_testimonials_wisdom_admin_emails' ) );
182
183 foreach ( $options_array as $db_option ) {
184 delete_option( $db_option );
185 }
186 }
187
188 // Delete transients
189 if ( 1 === absint( $uninstall_option['delete_transients'] ) ) {
190 // filter for transients to be added by Strong Testimonial's add-ons
191 $transients_array = apply_filters( 'st_uninstall_transients', array( 'wpmtst_mail_queue', 'strong_testimonials_all_extensions', 'wpmtst_update_in_progress', 'wpmtst_order_query' ) );
192
193 foreach ( $transients_array as $db_transient ) {
194 delete_transient( $db_transient );
195 }
196 }
197
198 // Delete custom post type
199 if ( 1 === absint( $uninstall_option['delete_cpt'] ) ) {
200
201 $post_types = apply_filters( 'st_uninstall_post_types', array( 'wpm-testimonial' ) );
202 $testimonials = get_posts(
203 array(
204 'post_type' => $post_types,
205 'posts_per_page' => -1,
206 'fields' => 'ids',
207 )
208 );
209
210 if ( is_array( $testimonials ) && ! empty( $testimonials ) ) {
211
212 // Prepare placeholders and values array
213 $placeholders = array_fill( 0, count( $testimonials ), '%d' );
214 $placeholders_string = implode( ',', $placeholders );
215
216 // phpcs:disable WordPress.DB.PreparedSQL
217 // Build SQL queries using placeholders and values array
218 $sql = $wpdb->prepare(
219 "DELETE FROM $wpdb->posts WHERE ID IN ($placeholders_string)", // phpcs:ignore
220 ...$testimonials
221 );
222
223 $sql_meta = $wpdb->prepare(
224 "DELETE FROM $wpdb->postmeta WHERE post_id IN ($placeholders_string)", // phpcs:ignore
225 ...$testimonials
226 );
227
228 // Execute queries
229 $wpdb->query( $sql );
230 $wpdb->query( $sql_meta );
231 // phpcs:enable WordPress.DB.PreparedSQL
232 }
233 }
234
235 global $wpdb;
236
237 if ( 1 === absint( $uninstall_option['delete_st_tables'] ) ) {
238 $st_views_table = $wpdb->prefix . 'strong_views';
239
240 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
241 // Direct query to drop table if exists
242 $sql_st_views_table = "DROP TABLE IF EXISTS $st_views_table";
243 $wpdb->query( $sql_st_views_table );
244 // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
245 }
246
247 if ( 1 === absint( $uninstall_option['delete_terms'] ) ) {
248 $term_type = apply_filters(
249 'st_uninstall_terms',
250 array(
251 'wpm-testimonial-category
252 ',
253 )
254 );
255 $testimonials = get_terms(
256 array(
257 'taxonomy' => 'wpm-testimonial-category',
258 'hide_empty' => false,
259 'fields' => 'tt_ids',
260 )
261 );
262
263 if ( is_array( $testimonials ) && ! empty( $testimonials ) ) {
264
265 // Creăm un string de ID-uri separate prin virgulă
266 $id_in = implode( ',', array_map( 'intval', $testimonials ) );
267
268 // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
269 // Direct query to delete terms and term taxonomy entries
270 $sql = "DELETE FROM $wpdb->terms WHERE term_id IN ($id_in)";
271 $sql_meta = "DELETE FROM $wpdb->term_taxonomy WHERE term_id IN ($id_in)";
272 $wpdb->query( $sql );
273 $wpdb->query( $sql_meta );
274 // phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
275 }
276 }
277
278 do_action( 'st_uninstall' );
279
280 deactivate_plugins( WPMTST_PLUGIN );
281 wp_die();
282 }
283 }
284
285 $st_uninstall = new Strong_Testimonials_Uninstall();
286