PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.5
Post Grid Gutenberg Blocks – PostX v5.0.5
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / Deactive.php

Deactive.php in Post Grid Gutenberg Blocks – PostX 5.0.5, at classes/Deactive.php

543 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Deactivation Action.
4 *
5 * @package ULTP\Notice
6 * @since v.1.1.0
7 */
8
9 namespace ULTP;
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * Deactive class.
15 *
16 * Handles plugin deactivation logic for Ultimate Post.
17 *
18 * @package ULTP\Deactive
19 * @since 4.0.0
20 */
21 class Deactive {
22
23 private $PLUGIN_NAME = 'PostX';
24 private $PLUGIN_SLUG = 'ultimate-post';
25 private $PLUGIN_VERSION = ULTP_VER;
26 private $API_ENDPOINT = 'https://inside.wpxpo.com';
27
28 /**
29 * Setup class.s
30 *
31 * @since v.1.1.0
32 */
33 public function __construct() {
34 global $pagenow;
35 if ( $pagenow == 'plugins.php' ) {
36 add_action( 'admin_footer', array( $this, 'get_source_data_callback' ) );
37 }
38 add_action( 'wp_ajax_ultp_deactive_plugin', array( $this, 'send_plugin_data' ) );
39 }
40
41 /**
42 * Get plugin data response.
43 *
44 * @since v.1.0.0
45 * @param STRING $type The type of deactivation.
46 * @param STRING $site The site type (optional).
47 * @return ARRAY Product return data.
48 */
49 public function send_plugin_data( $type, $site = '' ) {
50
51 if ( current_user_can( 'administrator' ) ) {
52 $data = $this->get_required_data();
53 $data['site_type'] = $site ? $site : get_option( '__ultp_site_type', '' );
54 $data['type'] = $type ? $type : 'deactive';
55 $form_data = isset($_POST) ? ultimate_post()->ultp_rest_sanitize_params($_POST) : array(); //phpcs:Ignore
56
57 if ( isset( $form_data['action'] ) ) {
58 unset( $form_data['action'] );
59 }
60 $response = wp_remote_post(
61 $this->API_ENDPOINT,
62 array(
63 'method' => 'POST',
64 'timeout' => 30,
65 'redirection' => 5,
66 'headers' => array(
67 'user-agent' => 'wpxpo/' . md5( esc_url( home_url() ) ) . ';',
68 'Accept' => 'application/json',
69 ),
70 'blocking' => true,
71 'httpversion' => '1.0',
72 'body' => array_merge( $data, $form_data ),
73 )
74 );
75
76 return $response;
77 }
78 }
79
80 /**
81 * Get deactivation form settings data.
82 *
83 * @since v.1.0.0
84 * @return ARRAY Settings parameters.
85 */
86 public function get_deactive_settings() {
87 $attr = array(
88 array(
89 'id' => 'no-need',
90 'input' => false,
91 'text' => __( 'I no longer need the plugin.', 'ultimate-post' ),
92 ),
93 array(
94 'id' => 'better-plugin',
95 'input' => true,
96 'text' => __( 'I found a better plugin.', 'ultimate-post' ),
97 'placeholder' => __( 'Please share which plugin.', 'ultimate-post' ),
98 ),
99 array(
100 'id' => 'stop-working',
101 'input' => true,
102 'text' => __( 'The plugin suddenly stopped working.', 'ultimate-post' ),
103 'placeholder' => __( 'Please share more details.', 'ultimate-post' ),
104 ),
105 array(
106 'id' => 'not-working',
107 'input' => false,
108 'text' => __( 'I could not get the plugin to work.', 'ultimate-post' ),
109 ),
110 array(
111 'id' => 'temporary-deactivation',
112 'input' => false,
113 'text' => __( "It's a temporary deactivation.", 'ultimate-post' ),
114 ),
115 array(
116 'id' => 'other',
117 'input' => true,
118 'text' => __( 'Other.', 'ultimate-post' ),
119 'placeholder' => __( 'Please share the reason.', 'ultimate-post' ),
120 ),
121 );
122 return $attr;
123 }
124
125 /**
126 * Output deactivation HTML view.
127 *
128 * @since v.1.0.0
129 * @return void No return value.
130 */
131 public function get_source_data_callback() {
132 $this->deactive_html_container();
133 $this->deactive_container_css();
134 $this->deactive_container_js();
135 }
136
137 /**
138 * Outputs the HTML container for the deactivation process.
139 *
140 * This method is responsible for rendering the necessary HTML
141 * when the plugin is being deactivated.
142 *
143 * @return void
144 */
145 public function deactive_html_container() {
146 ?>
147 <div class="ultp-modal" id="ultp-deactive-modal">
148 <div class="ultp-modal-wrap">
149
150 <div class="ultp-modal-header">
151 <h2><?php esc_html_e( 'Quick Feedback', 'ultimate-post' ); ?></h2>
152 <button class="ultp-modal-cancel"><span class="dashicons dashicons-no-alt"></span></button>
153 </div>
154
155 <div class="ultp-modal-body">
156 <h3><?php esc_html_e( 'If you have a moment, please let us know why you are deactivating PostX:', 'ultimate-post' ); ?></h3>
157 <ul class="ultp-modal-input">
158 <?php foreach ( $this->get_deactive_settings() as $key => $setting ) { ?>
159 <li>
160 <label>
161 <input type="radio" <?php echo $key == 0 ? 'checked="checked"' : ''; ?> id="<?php echo esc_attr( $setting['id'] ); ?>" name="<?php echo esc_attr( $this->PLUGIN_SLUG ); ?>" value="<?php echo esc_attr( $setting['text'] ); ?>">
162 <div class="ultp-reason-text"><?php echo esc_html( $setting['text'] ); ?></div>
163 <?php if ( isset( $setting['input'] ) && $setting['input'] ) { ?>
164 <textarea placeholder="<?php echo esc_attr( $setting['placeholder'] ); ?>" class="ultp-reason-input <?php echo $key == 0 ? 'ultp-active' : ''; ?> <?php echo esc_html( $setting['id'] ); ?>"></textarea>
165 <?php } ?>
166 </label>
167 </li>
168 <?php } ?>
169 </ul>
170 </div>
171
172 <div class="ultp-modal-footer">
173 <a class="ultp-modal-submit ultp-btn ultp-btn-primary" href="#"><?php esc_html_e( 'Submit & Deactivate', 'ultimate-post' ); ?><span class="dashicons dashicons-update rotate"></span></a>
174 <a class="ultp-modal-deactive" href="#"><?php esc_html_e( 'Skip & Deactivate', 'ultimate-post' ); ?></a>
175 </div>
176
177 </div>
178 </div>
179 <?php
180 }
181
182 /**
183 * Output deactivation forms CSS.
184 *
185 * @since v.1.0.0
186 * @return void No return value.
187 */
188 public function deactive_container_css() {
189 ?>
190 <style type="text/css">
191 .ultp-modal {
192 position: fixed;
193 z-index: 99999;
194 top: 0;
195 right: 0;
196 bottom: 0;
197 left: 0;
198 background: rgba(0,0,0,0.5);
199 display: none;
200 box-sizing: border-box;
201 overflow: scroll;
202 }
203 .ultp-modal * {
204 box-sizing: border-box;
205 }
206 .ultp-modal.modal-active {
207 display: block;
208 }
209 .ultp-modal-wrap {
210 max-width: 870px;
211 width: 100%;
212 position: relative;
213 margin: 10% auto;
214 background: #fff;
215 }
216 .ultp-reason-input{
217 display: none;
218 }
219 .ultp-reason-input.ultp-active{
220 display: block;
221 }
222 .rotate{
223 animation: rotate 1.5s linear infinite;
224 }
225 @keyframes rotate{
226 to{ transform: rotate(360deg); }
227 }
228 .ultp-popup-rotate{
229 animation: popupRotate 1s linear infinite;
230 }
231 @keyframes popupRotate{
232 to{ transform: rotate(360deg); }
233 }
234 #ultp-deactive-modal {
235 background: rgb(0 0 0 / 85%);
236 overflow: hidden;
237 }
238 #ultp-deactive-modal .ultp-modal-wrap {
239 max-width: 570px;
240 border-radius: 5px;
241 margin: 5% auto;
242 overflow: hidden
243 }
244 #ultp-deactive-modal .ultp-modal-header {
245 padding: 17px 30px;
246 border-bottom: 1px solid #ececec;
247 display: flex;
248 align-items: center;
249 background: #f5f5f5;
250 }
251 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel {
252 padding: 0;
253 border-radius: 100px;
254 border: 1px solid #b9b9b9;
255 background: none;
256 color: #b9b9b9;
257 cursor: pointer;
258 transition: 400ms;
259 }
260 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel:focus {
261 color: red;
262 border: 1px solid red;
263 outline: 0;
264 }
265 #ultp-deactive-modal .ultp-modal-header .ultp-modal-cancel:hover {
266 color: red;
267 border: 1px solid red;
268 }
269 #ultp-deactive-modal .ultp-modal-header h2 {
270 margin: 0;
271 padding: 0;
272 flex: 1;
273 line-height: 1;
274 font-size: 20px;
275 text-transform: uppercase;
276 color: #8e8d8d;
277 }
278 #ultp-deactive-modal .ultp-modal-body {
279 padding: 25px 30px;
280 }
281 #ultp-deactive-modal .ultp-modal-body h3{
282 padding: 0;
283 margin: 0;
284 line-height: 1.4;
285 font-size: 15px;
286 }
287 #ultp-deactive-modal .ultp-modal-body ul {
288 margin: 25px 0 10px;
289 }
290 #ultp-deactive-modal .ultp-modal-body ul li {
291 display: flex;
292 margin-bottom: 10px;
293 color: #807d7d;
294 }
295 #ultp-deactive-modal .ultp-modal-body ul li:last-child {
296 margin-bottom: 0;
297 }
298 #ultp-deactive-modal .ultp-modal-body ul li label {
299 align-items: center;
300 width: 100%;
301 }
302 #ultp-deactive-modal .ultp-modal-body ul li label input {
303 padding: 0 !important;
304 margin: 0;
305 display: inline-block;
306 }
307 #ultp-deactive-modal .ultp-modal-body ul li label textarea {
308 margin-top: 8px;
309 width: 350px;
310 }
311 #ultp-deactive-modal .ultp-modal-body ul li label .ultp-reason-text {
312 margin-left: 8px;
313 display: inline-block;
314 }
315 #ultp-deactive-modal .ultp-modal-footer {
316 padding: 0 30px 30px 30px;
317 display: flex;
318 align-items: center;
319 /* border-top: 1px solid #e5e5e5;
320 box-shadow: 0 0px 8px 0px rgb(0 0 0 / 12%); */
321 }
322 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit {
323 display: flex;
324 align-items: center;
325 }
326 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit span {
327 margin-left: 4px;
328 display: none;
329 }
330 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-submit.loading span {
331 display: block;
332 }
333 #ultp-deactive-modal .ultp-modal-footer .ultp-modal-deactive {
334 margin-left: auto;
335 color: #c5c5c5;
336 text-decoration: none;
337 }
338 .wpxpo-btn-tracking-notice {
339 display: flex;
340 align-items: center;
341 flex-wrap: wrap;
342 padding: 5px 0;
343 }
344 .wpxpo-btn-tracking-notice .wpxpo-btn-tracking {
345 margin: 0 5px;
346 text-decoration: none;
347 }
348 </style>
349 <?php
350 }
351
352 /**
353 * Output deactivation forms JS.
354 *
355 * @since v.1.0.0
356 * @return void No return value.
357 */
358 public function deactive_container_js() {
359 ?>
360 <script type="text/javascript">
361 jQuery( document ).ready( function( $ ) {
362 'use strict';
363
364 // Modal Radio Input Click Action
365 $('.ultp-modal-input input[type=radio]').on( 'change', function(e) {
366 $('.ultp-reason-input').removeClass('ultp-active');
367 $('.ultp-modal-input').find( '.'+$(this).attr('id') ).addClass('ultp-active');
368 });
369
370 // Modal Cancel Click Action
371 $( document ).on( 'click', '.ultp-modal-cancel', function(e) {
372 $( '#ultp-deactive-modal' ).removeClass( 'modal-active' );
373 });
374
375 // Deactivate Button Click Action
376 $( document ).on( 'click', '#deactivate-ultimate-post', function(e) {
377 e.preventDefault();
378 $( '#ultp-deactive-modal' ).addClass( 'modal-active' );
379 $( '.ultp-modal-deactive' ).attr( 'href', $(this).attr('href') );
380 $( '.ultp-modal-submit' ).attr( 'href', $(this).attr('href') );
381 });
382
383 // Submit to Remote Server
384 $( document ).on( 'click', '.ultp-modal-submit', function(e) {
385 e.preventDefault();
386
387 $(this).addClass('loading');
388 const url = $(this).attr('href')
389
390 $.ajax({
391 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
392 type: 'POST',
393 data: {
394 action: 'ultp_deactive_plugin',
395 cause_id: $('input[type=radio]:checked').attr('id'),
396 cause_title: $('.ultp-modal-input input[type=radio]:checked').val(),
397 cause_details: $('.ultp-reason-input.ultp-active').val()
398 },
399 success: function (data) {
400 $( '#ultp-deactive-modal' ).removeClass( 'modal-active' );
401 window.location.href = url;
402 },
403 error: function(xhr) {
404 console.log( 'Error occured. Please try again' + xhr.statusText + xhr.responseText );
405 },
406 });
407
408 });
409
410 });
411 </script>
412 <?php
413 }
414
415
416 /**
417 * Get all the installed plugin data.
418 *
419 * @since v.1.0.0
420 * @return ARRAY Plugin information.
421 */
422 public function get_installed_plugins() {
423 if ( ! function_exists( 'get_plugins' ) ) {
424 include ABSPATH . '/wp-admin/includes/plugin.php';
425 }
426
427 $active = array();
428 $inactive = array();
429 $all_plugins = get_plugins();
430 $active_plugins = get_option( 'active_plugins', array() );
431 if ( is_multisite() ) {
432 $active_plugins = array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', array() ) ) );
433 }
434
435 foreach ( $all_plugins as $key => $plugin ) {
436 $arr = array();
437
438 $arr['name'] = isset( $plugin['Name'] ) ? $plugin['Name'] : '';
439 $arr['url'] = isset( $plugin['PluginURI'] ) ? $plugin['PluginURI'] : '';
440 $arr['author'] = isset( $plugin['Author'] ) ? $plugin['Author'] : '';
441 $arr['version'] = isset( $plugin['Version'] ) ? $plugin['Version'] : '';
442
443 if ( in_array( $key, $active_plugins ) ) {
444 $active[ $key ] = $arr;
445 } else {
446 $inactive[ $key ] = $arr;
447 }
448 }
449
450 return array(
451 'active' => $active,
452 'inactive' => $inactive,
453 );
454 }
455
456 /**
457 * Get all the installed themes.
458 *
459 * @since v.1.0.0
460 * @return ARRAY Theme information.
461 */
462 public function get_installed_themes() {
463 $theme_data = array();
464 $all_themes = wp_get_themes();
465
466 if ( is_array( $all_themes ) ) {
467 foreach ( $all_themes as $key => $theme ) {
468 $attr = array();
469 $attr['name'] = $theme->Name;
470 $attr['url'] = $theme->ThemeURI;
471 $attr['author'] = $theme->Author;
472 $attr['version'] = $theme->Version;
473 $theme_data[ $key ] = $attr;
474 }
475 }
476 return $theme_data;
477 }
478
479 /**
480 * Get current user IP address.
481 *
482 * @since v.1.0.0
483 * @return STRING IP address.
484 */
485 public function get_user_ip() {
486 $response = wp_remote_get( 'https://icanhazip.com/' );
487 if ( is_wp_error( $response ) ) {
488 return '';
489 } else {
490 $user_ip = trim( wp_remote_retrieve_body( $response ) );
491 return filter_var( $user_ip, FILTER_VALIDATE_IP ) ? $user_ip : '';
492 }
493 }
494
495 /**
496 * Get all the collected data for deactivation.
497 *
498 * @since v.1.0.0
499 * @return ARRAY All send data.
500 */
501 public function get_required_data() {
502 global $wpdb;
503 $user = wp_get_current_user();
504 $user_count = count_users();
505 $plugins_data = $this->get_installed_plugins();
506
507 $data = array(
508 'name' => get_bloginfo( 'name' ),
509 'home' => esc_url( home_url() ),
510 'admin_email' => $user->user_email,
511 'first_name' => isset( $user->user_firstname ) ? $user->user_firstname : '',
512 'last_name' => isset( $user->user_lastname ) ? $user->user_lastname : '',
513 'display_name' => $user->display_name,
514 'wordpress' => get_bloginfo( 'version' ),
515 'memory_limit' => WP_MEMORY_LIMIT,
516 'debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No',
517 'locale' => get_locale(),
518 'multisite' => is_multisite() ? 'Yes' : 'No',
519
520 'themes' => $this->get_installed_themes(),
521 'active_theme' => get_stylesheet(),
522 'users' => isset( $user_count['total_users'] ) ? $user_count['total_users'] : 0,
523 'active_plugins' => $plugins_data['active'],
524 'inactive_plugins' => $plugins_data['inactive'],
525 'server' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_key( $_SERVER['SERVER_SOFTWARE'] ) : '',
526
527 'timezone' => date_default_timezone_get(),
528 'php_curl' => function_exists( 'curl_init' ) ? 'Yes' : 'No',
529 'php_version' => function_exists( 'phpversion' ) ? phpversion() : '',
530 'upload_size' => size_format( wp_max_upload_size() ),
531 'mysql_version' => $wpdb->db_version(),
532 'php_fsockopen' => function_exists( 'fsockopen' ) ? 'Yes' : 'No',
533
534 'ip' => $this->get_user_ip(),
535 'plugin_name' => $this->PLUGIN_NAME,
536 'plugin_version' => $this->PLUGIN_VERSION,
537 'plugin_slug' => $this->PLUGIN_SLUG,
538 );
539
540 return $data;
541 }
542 }
543